My harddrive was filling up, so I wanted to find the biggest files on my computer. I thought python would be the perfect language to do this, so I wrote a little script. The script starts in drive C:\, and recursively scans through every directory and file on your computer. If any file is larger than one Gigabyte, then it is put in a list. After every file has been scanned, then the program prints out the list of files larger than a Gigabyte. This is very useful for finding big files to clear your hard drive. Here is the code:
import os
def listdir(path):
good = []
try:
files = os.listdir(path)
count = 0
for i in files:
filepath = os.path.join(path,files[count])
byte = os.path.getsize(filepath)
gigabyte = byte / 1073741824
if(gigabyte >= 1):
good.append(filepath + " -- " + str(gigabyte) + "GB")
if(os.path.isdir(filepath)):
bbt = 0
tempt = listdir(filepath)
for p in tempt:
good.append(tempt[bbt])
bbt += 1
count += 1
except WindowsError, e:
print "Windows Error:"+str(e)
print " -- Continuing..."
return good
lists = listdir("C:\\")
count = 0
for i in lists:
print lists[count]
count += 1
I am, as we [well actually just me] speak, moving quite a few GB to our MyBook.
import os
def listdir(path):
good = []
try:
files = os.listdir(path)
count = 0
for i in files:
filepath = os.path.join(path,files[count])
byte = os.path.getsize(filepath)
gigabyte = byte / 1073741824
if(gigabyte >= 1):
good.append(filepath + " -- " + str(gigabyte) + "GB")
if(os.path.isdir(filepath)):
bbt = 0
tempt = listdir(filepath)
for p in tempt:
good.append(tempt[bbt])
bbt += 1
count += 1
except WindowsError, e:
print "Windows Error:"+str(e)
print " -- Continuing..."
return good
lists = listdir("C:\\")
count = 0
for i in lists:
print lists[count]
count += 1
I am, as we [well actually just me] speak, moving quite a few GB to our MyBook.