Re: openDir is confusing
John Reppy <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
readDir returns what is in the directory, while you might prefer an
absolute
path, others might want something different. There are two easy
solutions to
your problem. One is that you can change the working directory as
you walk the
tree, or you could implement your own version of directory streams:
structure MyDirstream =
struct
datatype dirstream = DS of {path : string, ds :
OS.FileSys.dirstream}
fun openDir s = DS{path = s, ds = OS.FileSys.openDir s}
fun readDir (DS{path, ds}) = (case OS.FileSys.readDir ds
of SOME f => SOME(OS.Path.concat(path, f))
| NONE => NONE
(* end case *))
fun closeDir (DS{ds, ...}) = OS.FileSys.closeDir ds
fun rewindDir (DS{ds, ...}) = OS.FileSys.rewindDir ds
end
On Nov 16, 2006, at 1:12 AM, brian wrote:
> I'm tyring to write a file tree "visitor" function and I find the
> operation of openDir/readDir to be somewhat hard to work with.
>
> An example is always good to start with:
>
>
> d = openDir("somelongpathname")
> readDir(d) => "foo" -- a file
> readDir(d) => "bar" -- a directory
>
> d2 = opendir("bar")
>
> error - no such file or directory
>
> Of course, this is correct, because I did not pass in the full
> pathname. Therein lies the problem, I think. It seems as I'm
> traversing the directory, I would have to maintain the path which
> readDir is operating from. So why doesn't readDir simply return the
> FULL path in the first place instead of just the pathname ?
>
> Am I missing something, or should I be using some different
> functionality ?
>
> Thanks
>
> Brian
>
>
> ----------------------------------------------------------------------
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
> share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV