Skip to content

Commit c06b3d1

Browse files
author
Broundon Seino
committed
google news python script
1 parent 72258af commit c06b3d1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/google_news.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Description : This will scan the current directory and all subdirectories and display the size.
2+
3+
import os
4+
import sys # Load the library module and the sys module for the argument vector'''
5+
try:
6+
directory = sys.argv[1] # Set the variable directory to be the argument supplied by user.
7+
except IndexError:
8+
sys.exit("Must provide an argument.")
9+
10+
dir_size = 0 # Set the size to 0
11+
fsizedicr = {'Bytes': 1,
12+
'Kilobytes': float(1) / 1024,
13+
'Megabytes': float(1) / (1024 * 1024),
14+
'Gigabytes': float(1) / (1024 * 1024 * 1024)}
15+
for (path, dirs, files) in os.walk(directory): # Walk through all the directories. For each iteration, os.walk returns the folders, subfolders and files in the dir.
16+
for file in files: # Get all the files
17+
filename = os.path.join(path, file)
18+
dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size.
19+
20+
fsizeList = [str(round(fsizedicr[key] * dir_size, 2)) + " " + key for key in fsizedicr] # List of units
21+
22+
if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file.
23+
else:
24+
for units in sorted(fsizeList)[::-1]: # Reverse sort list of units so smallest magnitude units print first.
25+
print ("Folder Size: " + units)

0 commit comments

Comments
 (0)