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 modifyextend the First.py script as follows:
Allow the user to specify a directory to process using the builtin Python input function
Process each entry in that directory and report:
FullFilepath, FileSize, MAC Times for each directory entry
Converting each MAC epoch value into human readable form
Catch any errors when attempting to process files and report them
HINTS
PROMPT USER FOR ENTRY
directory inputEnter a Directory to Process:
CONVERT EPOCH VALUES TO HUMAN READABLE UTC TIME
Epoch macTimes
utcTime time.strftimeYmd H:M:S time.gmtimemodEpoch
printutcTime IMPORT STANDARD LIBRARIES
import os # File System Methods
import sys # System Methods
import time # Time Conversion Methods
IMPORT RD PARTY LIBRARIES
# NONE
DEFINE PSEUDO CONSTANTS
# NONE
LOCAL FUNCTIONS
def GetFileMetaDatafileName:
obtain filesystem metadata
from the specified file
specifically, filesize and MAC Times
return True, None, filesize and MacTimeList
try:
metaData osstatfileName # Use the stat method to obtain meta data
filesize metaData.stsize # Extract filesize and MAC Times
timeLastAccess metaData.statime
timeLastModified metaData.stmtime
timecreated metaData.stctime
macTimeList timeLastModified timeLastAccess, timecreated # Group the MAC Times in a List
return True, None, filesize, macTimeList
except Exception as err:return False, strerr None, None
LOCAL CLASSES
# NONE
MAIN ENTRY POINT
if namemain:
print
WK Solution: YOUR NAME Version One
targetDIR inputEnter a Directory Path ie c:
print
try:
fileList oslistdirtargetDIR
for eachFile in fileList:
printeachFile
path ospath.jointargetDIR eachFile
printpath
success, errInfo, fileSize, macList GetFileMetaDatapath
printsuccess
printerrInfo
printfileSize
printmacList
print
#Add code as needed here
except Exception as err:
print
Script Aborted "Exception err
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
