Question

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

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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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

Add a comment
Know the answer?
Add Answer to:
Devise a Python script that takes two parameters to do the following:- 1) List all files...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT