Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python. show successful execution. last 2 screenshots are the code to help for the assignment. Create a new script with the following requirements: Allow the

image text in transcribed

image text in transcribed

image text in transcribed

python. show successful execution. last 2 screenshots are the code to help for the assignment.

Create a new script with the following requirements: Allow the user to specify a starting directory using the built-in Python input() function Using os.walk() Acquire the following information for each file (sub-directories included): File Path (absolute path) File Size MAC Times (in human readable form) SHA-256 Hash value Store the results in a prettytable with the headings: AbsPath, FileSize, LastModified, LastAccess. CreatedTime, HASH Display the prettytable sorted by FileSize Catch and report any errors Submit: 1) Your final script 2) A screenshot from within Wing|DE of a successful execution "IMPORT STANDARD LIBRARIES import os # File System Methods import sys # System Methods import time # Time Conversion Methods import hashlib # Python standard library hashlib IMPORT 3RD PARTY LIBRARIES from prettytable import PrettyTable # pip install prettytable DEFINE PSEUDO CONSTANTS #Change to directory as required DIR="c:/tst" *** 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) filesize - metadata,st_size timeLastAccess - metadata.st_atime timeLast Modified - metadata.st_atime timeCreated metadata.st_ctime # Use the stat method to obtain meta data # Extract filesize and MAC Times -2 53 macTimeList - (timeLastModified, tineLastAccess, timeCreated) # Group the MAC Times return True, None, filesize, sacTimeList a List except Exception as err: return false, str(err), None, None 55 56 67 68 69 70 71 72 73 74 "" LOCAL CLASSES": # NONE "MAIN ENTRY POINT": 1f name SE main': User Downloads Week 3 Heip.py f name _main_': try: # Perform the os.walk, starting at the target directory # TODO: Change this from a pseudo-constant to a user-specified directory using input() for root, dirs, filelist in os.walk(DIR): # Print current Root directory print('root: ', root) # Print current directory print('dirs: ', dirs) # Print file list print('files: ', filelist) # For each of the files in the file list, do the following: for nextFile in filelist: # Get the absolute path of the file--to be used for reporting and getting the file hash path - os.path.join(root, nextFile) absPath - os.path.abspath(path) # Call the GetFileMetadata function (from week 2 solution) success, errInfo, filesize, aucList - GetFilalletabuta(absPath) # Open each file in read binary mode with open(absPath, 'rb') as targetFile: # Read the contents of the file and get the file hash fileContents - targetFile.read() sha2560by - hashllb.sha256() sha2560bj.update(fileContents) hexDigest - sha2560bj.hexdigest() # Print stats for each file encountered # TODO: Format this output into a PrettyTable print("File name: ", absPath) print("Hex digest: ", hexDigest) print("Modified Time: ", time.strftime("%Y-%m-%d %H:%M:XS", time.gutime (macList[0])))) print("Accessed Time: "time.strftime("%Y-%m-%d %H:%:%s", time.gutime (macList[1]))) print("Created Time: ", time.strftime("%Y-%m-%d %H:%M:XS", time.gutime (macList[2]))) print("File size: ", filesize) print("-"*50) except Exception as err: print(" Script Aborted print("script end") "Exception = err)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions