Defining DIR?

Carl Sassenrath, CTO
REBOL Technologies
6-May-2010 14:17 GMT

Article #0319
Main page || Index || Prior Article [0318] || Next Article [0320] || 13 Comments || Send feedback

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 [
        process-file file

The problem is that dir? does two things:

  1. It checks if the filename ends with a slash (/).
  2. 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.


Updated 24-Jun-2024 - Edit - Copyright REBOL Technologies -