Devise a Python script that takes two parameters to do the following:- 1) List all files names, size, date created in the given folder 2) Parameter1 = Root Folder name Parameter2= File size >>> to filter file size ( you can do =, > or <) it is up to you, or a range. The script should check and validate the folder name, and the size The script should loop until find all files greater than the specified size in all the sub-folders 3) Use catch-exception block (Make sure that the error messages do not reveal any of the application code)
#import modules
import os,sys
import time,datetime,math
#take input from user
path = input("Enter path to the directory ")
s = int(input("Enter size in KB "))
size = s*1024
#function to print content
def getSize(p,size):
#iterate in all files in the given
path
for path, subdirs, files in os.walk(p):
#iterate for names
for name in files:
#join name and path to get full
path
fp= os.path.join(p,name)
#check for size
#if size is less than the given size then skip this file
if os.path.getsize(fp) < size:
continue
#print the name of file
print(name,end=" ")
#get creation time
timec = os.path.getctime(fp)
year,month,day,hour,minute,second=time.localtime(timec)[:-3]
#print time
print("Date created: %02d/%02d/%d
%02d:%02d:%02d"%(day,month,year,hour,minute,second), end=" ")
#get size in bytes
tt= os.path.getsize(fp)
#convert into KB and print size
final = math.ceil(tt/1024)
print(final,"KB")
print(" ")
#call function and handlle error
try:
getSize(path,size)
except:
print("Error handled! Please provide valid input")
===============
Code


Output

Devise a Python script that takes two parameters to do the following:- 1) List all files...