Created
August 24, 2015 09:45
-
-
Save wiig-with-a-k/1687483171981f6a120f 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.Security.Cryptography | |
type Config = | |
{ maxFileSize: int64 | |
startPath: string } | |
type FileResult = | |
{ hash: string | |
fullPath: string } | |
let filterTooSmallFiles maxFileSize files = | |
files | |
|> Seq.filter(fun f -> FileInfo(f).Length > maxFileSize) | |
let getChecksum file = | |
use stream = new BufferedStream(File.OpenRead(file), 1200000) | |
stream |> MD5.Create().ComputeHash | |
let rec getAllFiles dirPath = | |
seq { yield! Directory.GetFiles(dirPath) | |
for subDir in Directory.EnumerateDirectories(dirPath) do | |
yield! getAllFiles subDir } | |
let go config = | |
config.startPath | |
|> DirectoryInfo | |
|> fun di -> printfn "Finding files from your path: %s ..." di.FullName | |
config.startPath | |
|> getAllFiles | |
|> filterTooSmallFiles config.maxFileSize | |
|> Seq.map(fun f -> { hash = f |> getChecksum |> System.Text.Encoding.ASCII.GetString | |
fullPath = f }) | |
|> Seq.groupBy(fun f -> f.hash) | |
|> Seq.filter(fun (k, seq) -> seq |> Seq.length > 1) | |
|> Seq.iter(fun (k, seq) -> printfn "\nThe following files are the same:" | |
seq |> Seq.iter(fun f -> printfn "File: %s" f.fullPath)) | |
[<EntryPoint>] | |
let main args = | |
printfn "You have selected these parameters for this adventure: \n max size (bytes): %s \n and start path: %s" args.[0] args.[1] | |
printfn "\nPress the windows and apple key to continue" | |
System.Console.ReadKey() |> ignore | |
{ maxFileSize = int64 args.[0] | |
startPath = args.[1] } | |
|> go | |
printfn "\nPress the button on your keyboard labeled \"any key\" to close" | |
System.Console.ReadKey() |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment