Re: Equivalent of "du" utility in Unix or Sys module ?

"'Mr. Herr' [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>

On 21.06.2015 13:09, [email protected] [ocaml_beginners] wrote:
>
> In the ocaml interpreter, I can type
>
> Sys.command "du -d 1 pathformydirectory ";;
>
> to inspect the disk usage in a given directory.
>
> The problem is, the result is of type unit and I would prefer a result of type, 
> say, (string*int) list.
>
>  Is there a function from the Unix or Sys module that does this ?
>
If you do it right, you will get back a string from the command execution, or a 
string list, but not a (string*int) list.

You will have to scan the input.

Another proposal: why don't you just write "du" in OCaml?

Read the directory with Sys.readdir, make Unix.stat for every entry, go through the 
list,
for files collect the size, for directories you have to make Sys.readdir, make 
Unix.stat for every entry...

Get the idea? The perfect beginners project to get some list processing and recursion 
done, fully functional.

/Str.
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.