Something like this should work<br><br><pseudo-code><br>dirsize(Dir) -><br> {Dirs,Files} = listdir(Dir),<br> sum([filesize(File) || File <- Files]) % iterate over Files, collecting return values of filesize(<file>), then sum the list
<br> + sum([dirsize(Dir2) || Dir2 <- Dirs]). % ditto for for directories (recursively)<br></pseudo-code><br><br>Not so effective, but quite elegant, I hope ;-)<br><br>Does not detect circular links ...<br><br>
<div><span class="gmail_quote">On 9/18/07, <b class="gmail_sendername">Jarrod Roberson</b> <<a href="mailto:jarrod@vertigrated.com">jarrod@vertigrated.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am trying to grok how to write a simple 'du' like program that walks<br>a directory structure ( not just one but all nested directories ) and<br>calculates a sum of all the file sizes. I found some sum() code that I
<br>understand how that works.<br><br>I have stared at my Programming Erlang book I got a few days ago, and<br>stared at the Erlang Cookbook as well as staring and hacking at the<br>erlang shell and it just isn't clicking.
<br><br>>From what I see, this should be like a 5 line program in Erlang.<br><br>Can anyone provide a working example or point me in the correct direction?<br>_______________________________________________<br>erlang-questions mailing list
<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote>
</div><br>