From: Holden Glova Date: 2002-01-12T07:27:20+09:00 Subject: Re: Dir.entries have no home -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 12 Jan 2002 03:44, Ron Jeffries wrote: > Chet and I were writing a little code manager yesterday and we wrote > this code: > > def filesUnderManagement > names = (Dir.entries(@directoryName). > select { | each | ! (/.bak/ =~ each) }).sort > names.reject { |each| FileTest.directory?(each) } > end > > The idea was to have all the file names that weren't named *.bak > (which is a thing TextPad does) and weren't directories. > > So this seemed like reasonable code and passed all our tests. However, > as you may have noticed, being smarter than I am, the second line for > rejecting directories is looking at each name in the current working > directory, not the directory named in @directoryName. > > This worked on my machine, but not on Chet's, so he found the problem: > we have to attach the directory name back to the file name before we > test it. > > The same is true for opening it, and doing other things to it. > > So it seems to us that the names that come out of Dir.entries are, > well, bad. They have lost their connection to their home, and as we > all know, when we lose our home we have lost everything. > > Now one way I have dealt with this issue in the past is to go around > changing the working directory to whatever directory I'm thinking > about, but that seems to me to be a hack and a bug waiting to happen. > > I seem to recall that VisualWorks or some Smalltalk had a Filename > object and (I'm guessing) that object knew its full name or directory > or equivalent. I too have found file operations to cumbersome. It seems to me like my mind has to switch from this beautiful, OO, zen like programming flow to something that all of a sudden causes pain. For some reason file type/related operations often do tend to be awkward in many languages, let alone languages that attempt to platform independent. I feel your pain Ron, and I too am looking for a better way of handling/viewing this area. If you find a nicer solution please do let me know! - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8P2dk+mF116Lw2cQRAjy+AJwIsNEpilmTNWkPCbnUnZjAhM9f2wCfR13H OXjzOBb0vNdwBJQBj4PSXK8= =+bq8 -----END PGP SIGNATURE-----