-
-
Save isaacabraham/a76102f7ad67107561320fc4d9ca58c2 to your computer and use it in GitHub Desktop.
Sort subfolders by folder size in F#
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 | |
type FolderStatistic = { Name : string | |
Size : int64 } | |
let calculateFolderSize (folder : string) = | |
folder | |
|> Directory.GetFiles | |
|> Array.sumBy (fun file -> (FileInfo file).Length) | |
let getSubfolders path = | |
let folder = DirectoryInfo path | |
folder.GetDirectories("*", SearchOption.AllDirectories) | |
getSubfolders @"C:\Users\Isaac\Source\Repos\safe-test" | |
|> Array.map (fun x -> { Name = x.FullName; Size = calculateFolderSize x.FullName }) | |
|> Array.sortByDescending(fun x -> x.Size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment