REBOL 3.0

Solving the DIR? problem.

Carl Sassenrath, CTO
REBOL Technologies
20-Aug-2009 18:22 GMT

Article #0238
Main page || Index || Prior Article [0237] || Next Article [0239] || 16 Comments || Send feedback

I need your ideas on how best to solve the DIR? problem (bug #602).

The problem simply stated: if you specify a file name (or path) how do we determine if it is a directory.

The current algorithm is:

  1. Check if the name ends with "/" - if so, it refers to a directory.
  2. If it does not end with "/", check if the file exists, and if so, determine if it is a file or directory.

So, the algorithm mixes both the lexical check of the filename with the actual check of the local file.

There are two main problems with this:

  1. If the file name ends with "/", we just assume that it is a directory reference. However, locally a file of that name (without the /) may be present.
  2. It would be nice if the mechanism worked for URL's as well. So, when processing something like an HTTP request, we can use DIR? along the way. This is problematic if we check local storage, which in many cases is unrelated to the URL itself.

Although it would be nice to believe that there is a simple solution here, the compound behavior of the current DIR? function might cause more confusion than it's worth.

However, it would be nice to have a way to easily check file and URL paths. I often write:

if #"/" = last file-path [...]

and I'd prefer to write something a lot more clear, perhaps:

if dir-name? file-path [...]

or:

if is-dir? file-path [...]

Please let me know your comments soon. I realize it's still summer vacation, but dust that sand off your keyboard and post a comment.

16 Comments

REBOL 3.0
Updated 24-Dec-2024 - Edit - Copyright REBOL Technologies - REBOL.net