# File lib/win32/file.rb, line 405 def basename(file, suffix = nil) fpath = false file = file.dup # Don't modify original string # We have to convert forward slashes to backslashes for the Windows # functions to work properly. if file.include?('/') file.tr!('/', '\\') fpath = true end # Return an empty or root path as-is. if file.empty? || PathIsRoot(file) file.tr!("\\", '/') if fpath return file end PathStripPath(file) # Gives us the basename if suffix if suffix == '.*' PathRemoveExtension(file) else if PathFindExtension(file) == suffix PathRemoveExtension(file) end end end file = file.split(0.chr).first # Trim trailing slashes while file[-1].chr == "\\" file.chop! end # Return forward slashes if that's how the path was passed in. if fpath file.tr!("\\", '/') end file end