Skip to content

Commit a28393b

Browse files
authored
Create removeFile.py
1 parent bca9799 commit a28393b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

moumoubaimifan/remove/removeFile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import zlib
3+
import glob
4+
5+
def scanning_floder(glob_path):
6+
crc32Dict = {}
7+
for fname in glob.glob(glob_path, recursive=True):
8+
if os.path.isfile(fname):
9+
crc = crc32(fname)
10+
if crc in crc32Dict:
11+
print('已经存在文件:' + crc32Dict.get(crc))
12+
print('重复文件:' + fname)
13+
print('删除文件:' + fname)
14+
os.remove(fname)
15+
print('')
16+
else:
17+
crc32Dict[crc] = fname
18+
19+
def crc32(file_path):
20+
with open(file_path, 'rb') as f:
21+
hash = 0
22+
while True:
23+
s = f.read(1024)
24+
if not s:
25+
break
26+
hash = zlib.crc32(s, hash)
27+
return "%08X" % (hash & 0xFFFFFFFF)
28+
29+
scanning_floder("D:\personal\新建文件夹/**/*")

0 commit comments

Comments
 (0)