Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python windows modify and extend Windows pyare First Script: Obtain File Meta Data Enter File Path to Process: 1 M PM you are to modify/extend
python windows
modify and extend
Windows pyare First Script: Obtain File Meta Data Enter File Path to Process: 1 M PM you are to modify/extend the FirstScript.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 entry in the directory Convert each MAC epoch value into a human-readable form 3) Catch any errors when attempting to process files and report them. Review this was lectura you are to modify/extend the FirstScript.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 entry in the directory Convert each MAC epoch value into a human-readable form 3) Catch any errors when attempting to process files and report them. 8 ASSIGNMENT-DETAILS 9 After experimenting with the First.py script and attending this weeks lecture, you @ 1) Allow the user to specify a directory to process using the built-in-Python input -2 2) Process each entry in that directory and report: 33 Full-Filepath, -Filesize, MAC-Times for each directory entry 14 Converting each MAC epoch value into human readable form 15 3) Catch-any errors when attempting to process files and report them 16 17 LECTURE HINTS 18 19 PROMPT-USER FOR ENTRY 20 for directory =-input("Enter a Directory to Process:") 21 22 CONVERT EPOCHVALUES TO HUMAN READABLE UTC-TIME 23 Epoch macTimes[@] 24 --utcTime=time.strftime("%Y-%m-%d %H:%M:XS", time.gmtime(modEpoch)) 25 print(utcTime) 26 27 28 29 444-IMPORT STANDARD LIBRARIES 30 import os #-File System-Methods 31 import sys # System Methods 32 import time # Time Conversion Methods 33 34 ** IMPORT 3RD PARTY LIBRARIES!!! 35 # NONE 36 37 *** DEFINE PSEUDO CONSTANTS 38 39 # NONE 40 41 ** LOCAL FUNCTIONS. 42 43 def GetFileMetaData(fileName): 44 macfimelist [timelasthodified, timeLast Access, timecrested) Gro return True, Hone, filesize, mcTimeList except Exception as err: return false, str(err), -None, None "" LOCAL CLASSES ... # NONE 69 "MAIN ENTRY-POINT... if *_main_': 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 print(" Wk-2-Solution: - YOUR - NAME --Version-One ") targetDIR = Input('Enter a Directory Path i.e. c/ >>>') print() try: filelist - os. listdir(targetDER) for eachFile in fllelist: print(eachfile) path = 0s.path.join(targetDIR, eachFilo) .print(path) success, errInfo, filesize, macList - GetFileMetaData(path) 82 83 84 85 86 87 88 89 90 91 92 print(success) .print(arr Info) print(filesize) print(macList) print("-"*50) # Your additional script code here 94 95 96 except Exception as err: print(" Script Aborted...","Exception = err) A Select Python Internet CA Downloads Today WK-2-Help (1) py. Visual Studio Code File Edit Selection View GO Run Terminal Help WK-2-help (py X ) C > Users > daisy > Downloads > WK-2-Help (1).py 42 43 def GetFileMetaData(FileName) 44 45 46 47 48 obtain Filesystem metadata from the specified file specifically, filesize and MAC-Times return True, None, filesize and Mac TimeList trys se 51 52 53 54 55 56 57 58 59 60 61 52 metaData******* -os.stat(FileName) #-Use the stat method to obtain meta data filesize metadata.st_size=4 # Extract filesize and -MAC Times timeLastAccess - metadata.st_atime timeLast Modified = metadata.st_mtime timeCreated metaData.st_ctime macTimelist - [timeLast Modified, timeLastAccess, timeCreated] -Group the MAC-Times-in-a-List return-True, -None, filesize, macTimeList ch -except Exception as err: preturn false, str(err), None, Nona 54 65 66 67 68 69 *** LOCAL CLASSES". # NONE MAIN ENTRY-POINT *** if name__main__': w print(" K-2 Solution: -YOUR-NAME-Version One ") targetDIR = Input('Enter a Directory Path i.e. c/ >>>') print() 78 71 72 73 74 75 76 77 78 79 8e 81 82 trys filelist - os. listdir(targetDIR) for eachffle in filelist: print(eachFile) path. 05.path.join(targetDir. eachFile) print(path) 84 85 success, erinfo, Filesize, machist = GetFileMetaData(path) 86 print(success) 87 print(err Info) 88 print(Filesize) 89 print(maclist) 90 8 91 print(" "50) 92 93 Your additional script code here 94 95 except Exception as err: Select Python Interpreter 0A0 TUCIS.LOS AngelesTZEOD. AVID AFGESPEED.Correns 78 KB ME Find e Replace Select all S Picture Paint Date and insert drawing time object ragraph insett Editing 4 ASSIGNMENT DETAILS 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 LECTURE 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 w System Methods import time # Time Conversion Methods Find Replace Select all Picture Paint Date and Insert drawing time object Insert Editing 4 IT 1 "IMPORT 3RD PARTY LIBRARIES # NONE I DEFINE PSEUDO CONSTANTS # NONE LOCAL FUNCTIONS def GetFileMetaData(fileName): 11 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 timeLast Modified = metaData.st_mtime timeCreated = metaData.st_ctime mac Timelist = [timeLast Modified, timelastAccess, timeCreated) # Group the MAC Times 11 A Find Replace Select all Picture Paint Date and insert drawing time object Insert Editing 3 1 5 mac Timelist = [timeLast Modified, timelastAccess, timeCreated) # Group the MAC Times in a List return True, None, fileSize, mac TimeList 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) print/" WK 2 Solution: YOUR NAME-Version One ") target=input('Enter a Directory Pathie.cz/ >> printo try filelist os.listdirftarget DIR) for eachFile in filelist: print(eachFile) pathos.path join(targetDIR, eachFile) printipath success, errinfo, filesize, macust - GetFileMetaDataloathi printisuccess printferrinfo) print(fileSize printmaclist printsoj # Your additional script code here except Fxception as en print(" Script Aborted "Exception Serr)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started