Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: dir?

From: joel:neely:fedex at: 30-Jun-2002 7:16

Hi, Scott and Charles, G. Scott Jones wrote:
> From: "Charles" > > Okay, here's a question regarding the dir? function. > > Here's a little sample code: > > > > root: %/c/somedir/anotherdir/adir/ > > sub: %bdir/ > > foreach dir read join root sub [ > > if (dir? dir) AND (none? find dir "TN-") [ > > etcetcetc > > ] > > ] > > > > Problem is, when dir is, in fact, a directory, dir? is > > returning false. I've no idea why, and my only fix around > > it is to use (dir? rejoin [root sub dir]) .. > > Shouldn't dir? return true? It has in the past for me in a > > similar situation... *boggle* Help? > > Hi, Charles, > > I can more easily offer the fix rather than explain the problem. > The short answer is that REBOL needs the path. Try: > > root: %/c/ > sub: %rebol/ > foreach file read full-path: join root sub [ > if dir? join full-path file [print file] > ] > > Hope this gets you past the hurdle, but I, too, would like to > more fully understand the distinction. >
Relative file names always have to be interpreted in the context of some specific (absolute) directory if we're asking for info about actual files in the filesystem. Consider what you'd like REBOL to do if you ask dir? %temp Since there is no leading slash, this is a relative file name, and is interpreted relative to the *current*directory* (i.e., the output of WHAT-DIR). Therefore, if I say foreach filename read %someotherdirectory/ [ if dir? filename [print filename] ] I'm asking for a list of file names from someotherdirectory and then checking to see if there's a directory in the current active directory of the same name. To get a list of sub-directories within someotherdirectory I must either "absolutize" the relative file names to someotherdirectory: for each filename read %someotherdirectory/ [ if dir? join %someotherdirectory/ filename [print filename] ] or actually change to that directory: change-dir %someotherdirectory/ foreach filename read %./ [ if dir? filename [print filename] ] Hope that helps! -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]