We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f1adb27 commit a0d3aedCopy full SHA for a0d3aed
examples/find_dups.py
@@ -8,33 +8,20 @@
8
"""
9
10
from collections import defaultdict
11
-import hashlib
12
import sys
13
14
from fs import open_fs
15
16
17
-def get_hash(bin_file):
18
- """Get the md5 hash of a file."""
19
- file_hash = hashlib.md5()
20
- while True:
21
- chunk = bin_file.read(1024 * 1024)
22
- if not chunk:
23
- break
24
- file_hash.update(chunk)
25
- return file_hash.hexdigest()
26
-
27
28
hashes = defaultdict(list)
29
with open_fs(sys.argv[1]) as fs:
30
for path in fs.walk.files():
31
- with fs.open(path, "rb") as bin_file:
32
- file_hash = get_hash(bin_file)
+ file_hash = fs.hash(path, "md5")
33
hashes[file_hash].append(path)
34
35
for paths in hashes.values():
36
if len(paths) > 1:
37
for path in paths:
38
- print(f" {path}")
+ print(path)
39
print()
40
0 commit comments