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

dir?

 [1/8] from: chalz:earthlink at: 28-Jun-2002 22:18


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? --Charles

 [2/8] from: gscottjones:mchsi at: 30-Jun-2002 5:53


From: "Charles"
> Okay, here's a question regarding the dir? function. > Here's a little sample code:
<<quoted lines omitted: 7>>
> 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] ] (This sample is, of course, changed to something that I could run and show the results.) Hope this gets you past the hurdle, but I, too, would like to more fully understand the distinction. --Scott Jones

 [3/8] from: anton:lexicon at: 30-Jun-2002 22:07


Hi Charles, dir? only works in the current directory. If you look at the source of dir?, you will see that. Do this: ?? dir? Then do this: info? target where target is a file that is not in the current directory. It returns none, so your test always fails because none is not true. You should use the absolute path. foreach file read dir: join root sub [ if (dir? dir/:file) ... You can probably also use clean-path in other situations to get the absolute path. Anton.

 [4/8] 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.
<<quoted lines omitted: 23>>
> 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 ]

 [5/8] from: gscottjones:mchsi at: 30-Jun-2002 15:45


Anton:
<snip> > dir? only works in the current directory. > If you look at the source of dir?, you will > see that. Do this: <snip>
and separately... Joel:
<snip> > Relative file names always have to be
<<quoted lines omitted: 3>>
> the filesystem. <snip>
Thanks, Anton and Joel. You have certainly cleared up my ignorance, and in retrospect, it seems as though the "reason" should have been more obvious. Such is life. Thanks again. --Scott Jones

 [6/8] from: joel:neely:fedex at: 30-Jun-2002 16:48


Hi, self, Don't leave silly loopholes open! Joel Neely wrote:
> To get a list of sub-directories within someotherdirectory I must > either "absolutize" the relative file names to someotherdirectory:
<<quoted lines omitted: 6>>
> if dir? filename [print filename] > ]
That last example should have been written something like use [savedir] [ savedir: system/script/path change-dir %/c/ foreach filename read %./ [ if dir? filename [print filename] ] change-dir savedir ] just to follow the principle: If you move it, put it back when you've finished! which all good code should follow! -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 ]

 [7/8] from: chalz:earthlink at: 30-Jun-2002 22:31


Scott, Joel, thanks for your notes. It's being more or less what I expected. I have a sneaking suspicion that the reason why the script worked in one directory and not another is, uh, coz I executed it from that directory. I had, foolishly, assumed that if I told it to pull a file out of a specific directory listing, that it would use that file in the context of that directory. :/
> or actually change to that directory: > > change-dir %someotherdirectory/ > foreach filename read %./ [ > if dir? filename [print filename] > ] > > Hope that helps!
Aye. For my purposes, that might actually be best right there, unless I just kept join'ing 'file to the end of the dir every time ;) Thanks guys. Obvious mistake once I see it. --Charles

 [8/8] from: chalz:earthlink at: 30-Jun-2002 22:43


> dir? only works in the current directory. > If you look at the source of dir?, you will > see that. Do this: > > ?? dir?
I keep forgetting I can read the source of functions. Bah!
> You should use the absolute path.
Yeah, I learned that one now ;)
> foreach file read dir: join root sub [ > if (dir? dir/:file) ...
Oo, that's nicer looking..
> You can probably also use clean-path in other > situations to get the absolute path.
Cool. Thanks for the info! --Charles

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted