Created
August 17, 2010 08:18
-
-
Save robertpi/528925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.IO | |
open System.Collections.Generic | |
let rec getSize = | |
let memorize = new Dictionary<string, int64>() | |
fun dir -> | |
if memorize.ContainsKey(dir) then | |
memorize.[dir] | |
else | |
let size = | |
try | |
let dirSize = | |
Directory.GetFiles(dir) | |
|> Seq.map (fun path -> | |
let fi = new FileInfo(path) | |
fi.Length) | |
|> Seq.fold (+) 0L | |
Directory.GetDirectories(dir) |> Seq.fold (fun acc dir -> acc + (getSize dir)) dirSize | |
with _ -> 0L | |
memorize.Add(dir, size) | |
size | |
let printLargeDirs startDir limit = | |
let rec loop intend dir = | |
let size = getSize dir | |
printfn "%s %s: %iMB" dir intend (size / 1000000L) | |
if size > limit then | |
for dir in Directory.GetDirectories dir do | |
loop (intend + "\t") dir | |
loop "" startDir | |
[<EntryPoint>] | |
let main(args: array<string>) = | |
if args.Length <> 2 then | |
printfn "usage: startdir limit (mb)" | |
1 | |
else | |
printLargeDirs (args.[0]) ((int64 args.[1]) * 1000000L) | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment