From: Daniel Berger Date: 2005-09-14T03:31:14+09:00 Subject: Re: File.split edge cases Austin Ziegler wrote: > On 9/13/05, Daniel Berger wrote: > >>Yukihiro Matsumoto wrote: >> >>>Hi, >>>In message "Re: File.split edge cases" >>> on Wed, 14 Sep 2005 02:11:28 +0900, Daniel Berger >>> writes: >>>| I would argue that this should always be true: >>>| >>>| path == File.split(File.join(path)) >>>This sounds good, but it's kinda hard to define exact behavior for >>>related methods. I will examine posixpath.split in Python. >> >>Another interesting difference is the way Python interprets a trailing >>slash: > > > Assuming that File.split should be implemented as [ File.dirname, > File.basename ]: > > # Linux RedHat 9 2.4.20-8 > # coreutils 4.5.3 > % dirname /foo/bar/ > /foo > % basename /foo/bar/ > bar > % dirname / > / > % basename / > / > > # SunOS 5.8 Generic_117350-15 > % dirname /foo/bar/ > /foo > % basename /foo/bar/ > bar > % dirname / > / > % basename / > / Yeah, the closer I look at posixpath, the more I realize it's....wrong. Well, damn, with a name like "posixpath" you would *think* it would be correct, eh? > Ruby has it right in both cases. On Windows, File.split() should be a > bit smarter: > > File.split("C:\\") # => [ "C:", "\\" ] > File.split("\\\\server\\path\\") # => [ "\\\\server\\path", "\\" ] > > -austin Yes, I think really all that's needed are explicit checks for empty and root paths: # pseudo-code if path.root? or path.empty? return path, "" else return File.dirname(path), File.basename(path) end Regards, Dan