Skip to content

Commit 6f701f3

Browse files
committed
added disk space analyzer script
1 parent 547c343 commit 6f701f3

File tree

3 files changed

+68
-16
lines changed

3 files changed

+68
-16
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
3+
def get_size(path):
4+
total_size = 0
5+
if os.path.isfile(path):
6+
return os.path.getsize(path)
7+
elif os.path.isdir(path):
8+
for dirpath, dirnames, filenames in os.walk(path):
9+
for f in filenames:
10+
fp = os.path.join(dirpath, f)
11+
total_size += os.path.getsize(fp)
12+
return total_size
13+
14+
def analyze_disk_space(directory):
15+
files = []
16+
folders = []
17+
for entry in os.scandir(directory):
18+
if entry.is_file():
19+
size = get_size(entry.path)
20+
files.append((entry.name, size))
21+
elif entry.is_dir():
22+
size = get_size(entry.path)
23+
folders.append((entry.name, size))
24+
25+
sorted_files = sorted(files, key=lambda x: x[1], reverse=True)
26+
sorted_folders = sorted(folders, key=lambda x: x[1], reverse=True)
27+
28+
print("Files:")
29+
for file in sorted_files:
30+
name, size = file
31+
print(f"{name}: {size} bytes")
32+
33+
print("\nFolders:")
34+
for folder in sorted_folders:
35+
name, size = folder
36+
print(f"{name}: {size} bytes")
37+
38+
# Specify the directory to analyze
39+
directory = r"C:\Users\python" #insert your directory path here
40+
41+
# Analyze the disk space
42+
analyze_disk_space(directory)

Disk Space Analyzer/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Disk Space Analyzer
2+
3+
## Input
4+
<li>edit the directory path of a folder you want to analyze, defined by the 'directory' variable in the file.
5+
6+
## Output
7+
<li>list of all the sub folders and files with their size (in bytes) will be printed
8+
9+
## Author(s)
10+
[Prerna Mittal](https://github.com/prernamittal)

Readme.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# LINK SCRAPPER
2-
3-
4-
- It is used to scrape links from any website and display it.
5-
6-
7-
## Setup instructions
8-
9-
Any PC with python 3 installed can run this code.
10-
11-
12-
## Output
13-
image.png
14-
15-
## Author(s)
16-
1+
# LINK SCRAPPER
2+
3+
4+
- It is used to scrape links from any website and display it.
5+
6+
7+
## Setup instructions
8+
9+
Any PC with python 3 installed can run this code.
10+
11+
12+
## Output
13+
image.png
14+
15+
## Author(s)
16+
1717
Tanya Mohanka

0 commit comments

Comments
 (0)