From: Austin Ziegler Date: 2004-08-09T23:59:10+09:00 Subject: Changes to the semantics of basename/dirname? There are some issues with the way that File.basename and File.dirname work, at least on Windows. I also have an issue with File.expand_path related to some of the issues of File.basename and File.dirname. This may be present in more than just these, but these are what I've seen over the past few weeks. The first problem is that basename, dirname, and expand_path convert \\ to /. This shouldn't be problematic in the general case (where the path is then used in a Ruby command), but it would be useful to indicate that conversion should not be done. # Current, invalid behaviour p = "a\\b\\c\\d.txt" basename(p) #=> "d.txt" p1 = dirname(p) #=> "a/b/c" (should be "a\\b\\c") basename(p1) #=> "c" p2 = dirname(p1) #=> "a/b" (should be "a\\b") basename(p2) #=> "b" p3 = dirname(p2) #=> "a" basename(p3) #=> "a" p4 = dirname(p3) #=> "." basename(p4) #=> "." dirname(p4) #=> "." p = "\\a\\b\\c\\d.txt" basename(p) #=> "d.txt" p1 = dirname(p) #=> "/a/b/c" (should be "\\a\\b\\c") basename(p1) #=> "c" p2 = dirname(p1) #=> "/a/b" (should be "\\a\\b") basename(p2) #=> "b" p3 = dirname(p2) #=> "/a" (should be "\\a") basename(p3) #=> "a" p4 = dirname(p3) #=> "/" (should be "\\") basename(p4) #=> "/" (should be "\\") dirname(p4) #=> "/" (should be "\\") The second has to do with UNC/SMB share names. p = "\\\\host\\a\\b\\c\\d.txt" basename(p) #=> "d.txt" p1 = dirname(p) #=> "\\\\host\\a\\b\\c" basename(p1) #=> "c" p2 = dirname(p1) #=> "\\\\host\\a\\b" basename(p2) #=> "b" p3 = dirname(p2) #=> "\\\\host\\a" basename(p3) #=> "a" (should be "\\\\host\\a") p4 = dirname(p3) #=> "\\\\host" (should be "\\\\host\\a") basename(p4) #=> "host" (should be "\\\\host\\a") dirname(p4) #=> "\\\\" (should be "\\\\host\\a") In this specification, the base directory (the "device", if you will), is \\host\a, not \\ or \\host. Just as basename can never go above "/" in Unix, it should never go above \\hostname\sharename on Windows UNC shares. I'm not sure if URI special cases should be built in, but ftp://ruby-lang.org/pub/ruby would ultimately become "ftp:", which isn't desired -- but if it doesn't do that, then NetWare device support ("SYS1:\a\b\c\d.txt") would probably break. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca