Skip to content

Commit b8d5768

Browse files
authored
Merge pull request #264 from Sapna2001/folderSize
Folder Size
2 parents 5c6a328 + d12f27a commit b8d5768

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Python/Folder_Size/Readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Size of current directory
2+
3+
This script displays the size of the current directory in bytes, kilobytes, gigabytes, and megabytes.
4+
5+
## How to use this script?
6+
7+
Just type the following in your command prompt:
8+
9+
python script.py
10+
11+
## Sample of the script in action:
12+
13+
![demo](https://user-images.githubusercontent.com/56690856/98205431-28649780-1f5e-11eb-85d2-542681a98426.png)

Python/Folder_Size/script.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
# get the current directory directly
4+
currentDirectory = os.getcwd()
5+
6+
# or give the required path here
7+
# currentDirectory = r"C:\Users\Sapna\Desktop\hacking-tools-scripts\Python"
8+
9+
# initialize the size as 0
10+
directory_size = 0
11+
12+
# Size of the current directory in different formats
13+
sizeFormat = {'Bytes': 1,
14+
'Kilobytes': float(1)/1024,
15+
'Megabytes': float(1)/(1024*1024),
16+
'Gigabytes': float(1)/(1024*1024*1024)}
17+
18+
for (path, dirs, files) in os.walk(currentDirectory):
19+
for file in files:
20+
filename = os.path.join(path, file)
21+
directory_size += os.path.getsize(filename)
22+
23+
print("Size of current directory:"+ currentDirectory)
24+
25+
# directory size in bytes, kilobytes, megabytes and gigabytes
26+
for key in sizeFormat:
27+
print (str(round(sizeFormat[key]*directory_size, 2)) + " " + key)

0 commit comments

Comments
 (0)