-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathlarge_file_identifier.py
More file actions
49 lines (40 loc) · 1.64 KB
/
large_file_identifier.py
File metadata and controls
49 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
def searchFolder(location, min_file_size):
fileNotFound = 0
filesFoundCount = 0
total_size = 0
print(f"Files larger than {min_file_size:.2f} MB in location: {location}")
for foldername, subfolders, filenames in os.walk(location):
for filename in filenames:
try:
actual_size = os.path.getsize(os.path.join(foldername, filename))
if min_file_size * 1024 ** 2 <= actual_size:
print(
f"{foldername}\\{filename} - " f"{(actual_size/1024**2):.2f} MB"
)
yield foldername, filename, actual_size
filesFoundCount += 1
total_size += actual_size
except FileNotFoundError:
fileNotFound += 1
print(f"FileNotFoundError: {filename}")
print(f"Files found: {filesFoundCount}")
print(f"Total size: {(total_size/1024**2):.2f} MB")
if fileNotFound > 0:
print(f"FileNotFoundErrors: {fileNotFound}")
if __name__ == "__main__":
while True:
location = input("Where would you like to search? ")
if os.path.exists(location):
break
else:
print("Please enter a valid path.")
while True:
try:
min_file_size = float(input("Please enter file size in MB: "))
break
except ValueError:
print("Please enter numeric input only.")
searchFolder(location, min_file_size)
for foldername, filename, actual_size in searchFolder(location, min_file_size):
print(f"{foldername}\\{filename} - {(actual_size/1024**2):.2f} MB")