Question: Make a simple Python application (Save as w5_firstname_lastname.py) . make a Python script that takes two parameters to do the following:- 1)List all files names,
Make a simple Python application (Save as w5_firstname_lastname.py) .
make 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 try-exception block (Make sure that the error messages do not reveal any of the application code)
Create the following code but keep receiving an error, Also I'm trying to run the file from CMD and do not know the correct format that will properly run it and show file details. Please check the code for errors and help me with the CMD script to run the file showing what the file contains.
import os, sys, time
try:
path = "." #parameter 1, Root Folder
dirs = os.listdir(path)
except IOError:
print("Error: can't find file or read data")
else:
toolarge = 0
print(str("FILE").ljust(34), str("SIZE").ljust(16), str("DATE CREATED").ljust(10), end=" ")
print("------------------ ------------ -----------------")
for file in dirs:
filesize = os.stat(file).st_size #parameter 2, file size
if (filesize <= 10000): #file size filter to files <= 10000 bytes
print(str(file).ljust(30), repr(os.stat(file).st_size).rjust(8), end = ' ')
print("bytes", str(time.ctime(os.path.getctime(file))).rjust(30))
else:
toolarge = toolarge + 1
print("There are", toolarge, "files that exceed directory filter paramteres.")
Step by Step Solution
There are 3 Steps involved in it
Answer Code to Copy save as w5firstnamelastnamepy import modules import ossys import timedatetimemat... View full answer
Get step-by-step solutions from verified subject matter experts
