-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
51 lines (39 loc) · 1.13 KB
/
code.py
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
50
51
import os
from os.path import join
def get_human_size(file_size):
"""
Provides a human-readable size from the
given file size (in bytes).
:param int file_size:
The file size to convert.
:rtype: str
"""
for human_size_description in [
"bib",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB",
"ZiB",
"YiB",
]:
if file_size < 1024:
human_size = f"{file_size:3.1f}{human_size_description}"
break
file_size /= 1024.0
return human_size
if __name__ == "__main__":
search_location = str(input("Directory Location : ")).strip()
extension = str(input("Extension of files to search for : ")).strip()
if extension.startswith("."):
extension = extension[1:]
for dirname, _, files in os.walk(search_location):
for filename in files:
if filename.endswith(f".{extension}"):
the_file = os.path.join(dirname, filename)
print(
get_human_size(os.path.getsize(the_file)),
the_file,
)