OS.FileSys and recursive procedures ?

brian denheyer <briand-/[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.