Skip to content

Instantly share code, notes, and snippets.

@manuelsidler
Created June 21, 2018 18:48
Show Gist options
  • Save manuelsidler/1eefd1b9db1e477758e145256c719c60 to your computer and use it in GitHub Desktop.
Save manuelsidler/1eefd1b9db1e477758e145256c719c60 to your computer and use it in GitHub Desktop.
Sort subfolders by folder size in F#
open System.IO
type FolderStatistic = { Name : string
Size : int64 }
let calculateFolderSize (folder : string) =
Directory.GetFiles folder
|> List.ofSeq
|> List.sumBy (fun f -> FileInfo(f).Length)
let subfolders : DirectoryInfo array =
let folder = new DirectoryInfo(@"C:\\tmp")
folder.GetDirectories()
subfolders
|> List.ofArray
|> List.map (fun x -> { Name = x.Name; Size = calculateFolderSize x.FullName })
|> List.sortByDescending(fun x -> x.Size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment