2017-11-08 18:21:39 +08:00
|
|
|
#!python3
|
2017-11-14 18:01:55 +08:00
|
|
|
# deleting_unneeded_files.py - walks through a folder tree and searches for
|
|
|
|
|
# exceptionally large files or folders. say, ones that have a file size of more
|
|
|
|
|
# than 100MB. Print these files with their absolute path to the screen.
|
2017-11-08 18:21:39 +08:00
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
|
2017-11-14 18:01:55 +08:00
|
|
|
|
2017-11-08 18:21:39 +08:00
|
|
|
def deleting_large_files(fd, mega):
|
|
|
|
|
for foldername, subfolders, filenames in os.walk(fd):
|
|
|
|
|
for filename in filenames:
|
|
|
|
|
filepath = os.path.join(foldername, filename)
|
|
|
|
|
size = os.path.getsize(filepath)
|
|
|
|
|
size /= 1024 * 1024
|
|
|
|
|
if size > mega:
|
|
|
|
|
print(filepath)
|
2017-11-14 18:01:55 +08:00
|
|
|
# os.unlink(filepath)
|
2017-11-08 18:21:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
deleting_large_files("D:\\BaiduNetdiskDownload", 10)
|