Beginning python class, writing a simple script. I cannot figure out why my script is getting path not defined exception
Attached Files
Simple Python script, path not defined
|
Beginning python class, writing a simple script. I cannot figure out why my script is getting path not defined exception
Attached Files
Nov-06-2021, 05:26 PM
Error
WK-2 Attempt: Steve K Dubina - Version 1.e Week 2 Assignment: Steve Dubina Version 1.e Enter a Directory Path i.e. c:/ >>> d: ======================================== $RECYCLE.BIN Script Aborted Exception = name 'path' is not defined
Nov-06-2021, 06:15 PM
(This post was last modified: Nov-06-2021, 06:15 PM by Gribouillis.)
Don't catch exceptions, let them propagate to see where the error comes from. For example, add a
raise statement after the last print.And, as Yoriz wrote above, please post the code between bbcode tags.
There are serval problems in code,you should test code in smaller parts and without exceptions as mention(want to see all errors when testing stuff out).
To take out part and do a quick test, timeLastAcess spell error in macTimeList.import os # File System Methods import sys # System Methods import time # Time Conversion Methods def GetFileMetaData(fileName): ''' obtain filesystem metadata from the specified file specifically, fileSize and MAC Times return True, None, fileSize and MacTimeList ''' 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] # Output MAC Times in a List return True, None, fileSize, macTimeList if __name__ == '__main__': targetDIR = r'G:\div_code\outdir' fileList = os.listdir(targetDIR) for eachEntry in fileList: print("="*40) #print(eachEntry) fullPath = os.path.join(targetDIR, eachEntry) print(fullPath) success, errInfo, fileSize, macList = GetFileMetaData(fullPath) So iterating over file works.Line 30 here will only get info of last file in the loop. success, errInfo, fileSize, macList = GetFileMetaData(fullPath) >>> success True >>> errInfo >>> fileSize # Only last file in loop,all info of files before is now lost 586 >>> macList [1628441571.5508275, 1630179742.932314, 1628440434.2352946] # Only last file in loop |
|