I want to get the total directory size, including all sub-directories and files. There are two ways I can think to do this, the first is to get a list of all the file attributes (FileInfo in .NET) of all the files, and then just sum together all the Length properties like this:
listOfFileInfos |> List.sumBy (fun f -> f.Length)
The other way would be to add the file size of each file to an accumulator as we traverse the directory structure. So we wouldn't be building a big list, we'd just be adding to the total as we go. I'm not really sure how to do this in F# though!
Which way is more idiomatic? The first one looks easier to me but I'm only a beginner in functional programming.