Re: OS.FileSys and recursive procedures ?
brian denheyer <briand-/[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
Hi John,
The following code just doesn't work as expected...
fun loopDir(dir_name) =
let val d = FS.openDir(dir_name)
fun entries() =
let val r = FS.readDir(d)
in
case r of
NONE => print "NONE\n"
| SOME s =>
(if FS.isDir(s) then
print ("DIR:"^s^"\n")
else if FS.isLink(s) then
print ("LINK:"^s^"\n")
else
print ("FILE:"^s^"\n");
entries())
end
in
entries()
end
The idea, of course, is that entries loops until NONE comes back.
I run the above using something like :
loopDir(path)
It always succeeds on the first readDir and then ALWAYS fails on the
second readDir.
However if I do a :
chDir(path)
loopDir(path)
Then it works as expected.
???
Brian
On Jan 22, 2006, at 9:22 PM, John Reppy wrote:
> Are you sure that you have read and execute permission on the
> directory in
> question?
>
> - John
>
> On Jan 22, 2006, at 11:06 PM, brian denheyer wrote:
>
>> The following function does not seem to work correctly :
>> (you'll need structure FS = OS.FileSys to make it run)
>>
>> fun loopDir(dir) =
>> (print "loopDir\n";
>> let val d = FS.readDir(dir)
>> in
>> case d of
>> NONE => (print "none\n";
>> FS.closeDir(dir))
>> | SOME s => (if FS.isDir(s) then
>> (print ("Dir:'"^s^"'\n");
>> print ("full path:"^FS.fullPath(s)
>> ^"\n");
>> loopDir(FS.openDir(s));
>> ())
>> else if FS.isLink(s) then
>> print ("Link:'"^s^"'\n")
>> else
>> (print ("File:"^s^"\n");
>> File(s));
>> loopDir(dir))
>>
>> end
>>
>> I start the loop with loopDir(FS.openDir("."))
>>
>> Eventually I get a file doesn't exist error !
>> Through the use of the prints I have identified that the val d =
>> statement is
>> failing with a "no such file or directory error".
>>
>> That's pretty much impossible as far as I can tell. Notice that
>> the openDir
>> has already been done and is being passed into the loop. The only
>> possible answers
>> are a file of some sort, or NONE, the openDir has already been
>> performed and the directory mus exist or the FS.isDir would not
>> have succeeded.
>>
>> It's definitely the recursive invocation which is causing
>> problems. In other words,
>> if I perform the readDir BEFORE recursively invoking the loop, it
>> is sucessful
>> and gives the expected results.
>>
>> This is on MAC OS X 10.4.4
>>
>> Thanks
>>
>> Brian
>>
>> P.S. Is this list still alive ? have not seen anything in a long
>> time...
>>
>>
>>
>>
>> -------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc. Do you grep through
>> log files
>> for problems? Stop! Download the new AJAX search engine that makes
>> searching your log files as easy as surfing the web. DOWNLOAD
>> SPLUNK!
>> http://sel.as-us.falkag.net/sel?
>> cmd=lnk&kid=103432&bid=230486&dat=121642
>> _______________________________________________
>> Smlnj-list mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through
> log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD
> SPLUNK!
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642