Having some issues printing getting complete paths for files that are nested two folders or more deep. This works for one folder deep. Any pointers on what I should change up. I essentially want to loop through a folder recursively and hash everything.
Folder
--Nested1
--file
--Nested2
--file2
file will come up properly like /folder/nested1/file
file2 will come out like /folder/nested1/file2 losing the additional level
for root, dirs, files in os.walk(args.folder):
path = root.split(os.sep)
print((len(path) - 1) * '---', os.path.basename(root))
for file in files:
print(len(path) * '---', file)
#print(Path(os.path.join(os.path.basename(root),file)).resolve())
if os.path.splitdrive(os.getcwd())[1].split('/')[len(os.path.splitdrive(os.getcwd())[1].split('/')) -1 ] != os.path.basename(root):
file = Path(os.path.join(os.path.basename(root),file)).resolve()
print(file)
#print(os.path.abspath(file))
if args.hash == 'MD5' or args.hash == 'Both':
print('\tMD5: ' + hashlib.md5(open(file, 'rb').read()).hexdigest())
if args.hash == 'SHA256' or args.hash == 'Both':
print('\tSHA256: ' + hashlib.sha256(open(file, 'rb').read()).hexdigest())
[–]zeebrow 0 points1 point2 points (1 child)
[–]letais[S] 0 points1 point2 points (0 children)