Comments on: Defining DIR?
The dir? function is intended to be an easy-to-use way to check if a file or file path is a directory.
For example, when processing a list of files we often write:
foreach file file-list [
unless dir? file [
The problem is that dir? does two things:
- It checks if the filename ends with a slash (/).
- It checks if the file is a directory on local storage.
This behavior is problematic because the filenames being checked may have nothing to do with local storage. In the example above, the list of files may have been fetched from a server or a database, and they're not related to what's on disk.
So, we need to define dir? a little better. It should do one of the above operations, but not both.
Personally, I'd prefer the first behavior, because that's what I use the most. I never do the second, because I'm using filenames that were obtained from a directory, so they contain the slash in their names. However, that's not compatible with R2.
The second behavior could be supported with a refinement, like dir?/query which would perform the actual disk query.
isn't DIR? already just checking the path?
I thought we had resolved that one a few years ago...
>> dir? %/path/does/not/exist/
PLEASE do not re-introduce the old R2 behaviour its useless.
it got replaced by exists? returning 'dir 'file or none
>> exists? %/path/does/not/exist/
Hi Maxim, no it does both... but you may not have noticed because it did the path string check first.
However, bug #602 shows the problem. A file %foo could be a directory on disk, in which case DIR? returns true.
My proposal is to simplify, and make it just check the path string and not go to disk.
oh... well, the current behavior is even less meaningull then ;-)
yep, slash the file access, and I don't see any need to add the /QUERY refinement.
we've got EXISTS? for that, and its a sexy function which you can even use directly with SWITCH or CASE.
Sounds good. A99 will change it.
If anyone has opposing opinions, post them really soon.
Add a refinement for a comparator if needed (or use generator for dir? closures)
Comparator as in a sort function.|
If the purpose of dir? is to check for a trailing /, then it's misnamed. Perhaps rename it to tail/? or something.|
Adding a refinement for a comparator is a little heavy for what would be a one-line mezzanine - what do you mean Maarten, in REBOL code? And tail/? isn't a valid word Graham, it's a path, so "or something" would be better.
Having dir? just work on the filename, and exists? check the file works for me. We need both operations on different occasions, whatever we end up calling dir?.
Just to say I'm relieved at this decision.
I would also like to mention that in the beginning, I was confused by file? being a type check and dir? checking storage. Having dir? act as a subtype check is much more elegant.
Having dir? check for a trailing / means it is true for a string such as "sfsf/" but false for "c:\windows\" ... so I think a better name is needed.
The dir? function checks for both / and \, so your concern is handled, Graham.|
Post a Comment:
You can post a comment here. Keep it on-topic.