Skip to content

Instantly share code, notes, and snippets.

@robertpi
Created August 17, 2010 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpi/528925 to your computer and use it in GitHub Desktop.
Save robertpi/528925 to your computer and use it in GitHub Desktop.
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