Question: After experimenting with the First.py script and attending this weeks lecture, you are to modify / extend the First.py script as follows: 1 ) Allow

After experimenting with the First.py script and attending this weeks lecture, you are to modify/extend the First.py script as follows:
1) Allow the user to specify a directory to process using the built-in Python input() function
2) Process each entry in that directory and report:
Full-Filepath, FileSize, MAC Times for each directory entry
Converting each MAC epoch value into human readable form
3) Catch any errors when attempting to process files and report them
HINTS
PROMPT USER FOR ENTRY
directory = input("Enter a Directory to Process: ")
CONVERT EPOCH VALUES TO HUMAN READABLE UTC TIME
Epoch= macTimes[0]
utcTime= time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(modEpoch))
print(utcTime)'' IMPORT STANDARD LIBRARIES
import os # File System Methods
import sys # System Methods
import time # Time Conversion Methods
'"' IMPORT 3RD PARTY LIBRARIES '"'
# NONE
'" DEFINE PSEUDO CONSTANTS '"'
# NONE
'" LOCAL FUNCTIONS '"'
def GetFileMetaData(fileName):
obtain filesystem metadata
from the specified file
specifically, filesize and MAC Times
return True, None, filesize and MacTimeList
try:
metaData = os.stat(fileName) # Use the stat method to obtain meta data
filesize = metaData.st_size # Extract filesize and MAC Times
timeLastAccess = metaData.st_atime
timeLastModified = metaData.st_mtime
timecreated = metaData.st_ctime
macTimeList =[timeLastModified, timeLastAccess, timecreated] # Group the MAC Times in a List
return True, None, filesize, macTimeList
except Exception as err:return False, str(err), None, None
''' LOCAL CLASSES '''
# NONE
''' MAIN ENTRY POINT '''
if __name__=='__main__':
print("
WK-2 Solution: YOUR NAME - Version One
")
targetDIR = input('Enter a Directory Path i.e. c:/>>>')
print()
try:
fileList = os.listdir(targetDIR)
for eachFile in fileList:
print(eachFile)
path = os.path.join(targetDIR, eachFile)
print(path)
success, errInfo, fileSize, macList = GetFileMetaData(path)
print(success)
print(errInfo)
print(fileSize)
print(macList)
print("="*50)
#Add code as needed here
except Exception as err:
print("
Script Aborted ", "Exception =", err)
 After experimenting with the First.py script and attending this weeks lecture,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!