Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Find-duplicate-files/Julia/find-duplicate-files.julia
Normal file
45
Task/Find-duplicate-files/Julia/find-duplicate-files.julia
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using Printf, Nettle
|
||||
|
||||
function find_duplicates(path::String, minsize::Int = 0)
|
||||
filesdict = Dict{String,Array{NamedTuple}}()
|
||||
|
||||
for (root, dirs, files) in walkdir(path), fn in files
|
||||
filepath = joinpath(root, fn)
|
||||
filestats = stat(filepath)
|
||||
|
||||
filestats.size > minsize || continue
|
||||
|
||||
hash = open(f -> hexdigest("md5", read(f)), filepath)
|
||||
|
||||
if haskey(filesdict, hash)
|
||||
push!(filesdict[hash], (path = filepath, stats = filestats))
|
||||
else
|
||||
filesdict[hash] = [(path = filepath, stats = filestats)]
|
||||
end
|
||||
end
|
||||
|
||||
# Get duplicates
|
||||
dups = [tups for tups in values(filesdict) if length(tups) > 1]
|
||||
|
||||
return dups
|
||||
|
||||
end
|
||||
|
||||
function main()
|
||||
path = "."
|
||||
println("Finding duplicates in \"$path\"")
|
||||
dups = find_duplicates(".", 1)
|
||||
|
||||
println("The following group of files have the same size and the same hash:\n")
|
||||
println("File name Size last modified")
|
||||
println("="^76)
|
||||
|
||||
for files in sort(dups, by = tups -> tups[1].stats.size, rev = true)
|
||||
for (path, stats) in sort(files, by = tup -> tup.path, rev = true)
|
||||
@printf("%-44s%8d %s\n", path, stats.size, Libc.strftime(stats.mtime))
|
||||
end
|
||||
println()
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue