|
Pages: [1]
|
 |
|
Author
|
Topic: Manipulating files in subdirectories (Read 719 times)
|
|
Stoop
|
I have a subdirectory off my REBOL directory called serverlogs.
I want to be able to get at these log files, but don't want to have to use change-dir system/options/path/serverlogs
So, what does work is that when I do a:
foreach file read %serverlogs/ [print file]
Sure enough I get a print out of the filenames, but if I try and do something else in my program like read in the lines of the files with something like:
foreach file read %serverlogs [lines: read/lines file]
I get the following error ** Access Error: Cannot open /C/rebol/serverlogs ** Near: foreach file read %serverlogs [lines: read/lines file]
Doesn't the lines: assignment know that the files are in a subdirectory?
How do I change this so it works - all the examples I see online use change-dir, and I don't wan to do that.
Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
Reading a directory creates a block containing the file-names and directory-names in the directory, but not their full paths. The solution to your problem is to join the path to the file-name. ie...
... [lines: read/lines join %/C/rebol/serverlogs/ file]
If needs be, you can get the path to the current directory using WHAT-DIR. So alternatives to the above could be...
... [lines: read/lines rejoin [what-dir %serverlogs/ file]]
or ...
path: join what-dir %serverlogs/ ... ... [lines: read/lines join path file]
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
|
Stoop
|
OK, so the block doesn't hold full-path information.
Thanks very much for clarifying that and for the examples - most appreciated.
Stuart
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |