Just looking for some feedback. I designed a script to find big files that are taking up lots of space. Still a beginner, and appreciative of constructive feedback, with both the function and form/style/formatting.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# findlargefiles.py Searches a file location and subdirectories for
# files larger than a given size.
"""
findlargefiles.py Searches a file location and subdirectories for
files larger than a given size.
Created on Sun Sep 3 20:35:12 2017
@author: toonarmycaptain
"""
import os
def searchfolder(location, filesize):
FileNotFoundErrorsCount = 0
filesfoundcount = 0
print('Files larger than '+str(int(filesize))+' MB in location: '+location)
for foldername, subfolders, filenames in os.walk(location):
for filename in filenames:
try:
actualsize = os.path.getsize(os.path.join(foldername,
filename))
if filesize*1024**2 <= actualsize:
print(foldername
+ '\\' # file path + \ + file name
+ filename
+ ' - '
+ '{:.2f} MB'.format(actualsize/1024**2))
filesfoundcount += 1
except FileNotFoundError:
FileNotFoundErrorsCount += 1
print('FileNotFoundError: '+filename)
print('Files found: '+str(filesfoundcount))
if FileNotFoundErrorsCount > 0:
print('FileNotFoundErrors: '+str(FileNotFoundErrorsCount))
print('This program searches for files larger than a given size '
'in a given location.')
while True:
location = input("Where would you like to search? ")
if os.path.exists(location):
break
else:
print('Please enter a valid path.')
filesize = float(input('Please enter file size in MB: '))
searchfolder(location, filesize)