I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program?
For example:
import os
def index(directory):
stack = [directory]
files = []
while stack:
directory = stack.pop()
for file in os.listdir(directory):
fullname = os.path.join(directory, file)
if fullname.endswith('mp3'):
files.append(fullname)
if os.path.isdir(fullname) and not os.path.islink(fullname):
stack.append(fullname)
return files
def check(directory):
files = index(directory)
hvalues = []
for x in files:
cmd = 'md5sum' + ' ' + x
fp = os.popen(cmd)
res = fp.readline()
hvalues.append(res)
stat = fp.close() # What to do with stat?
return hvalues
Command cmd = 'md5sum' + ' ' + x won't work as it should on files that include whitespaces or special characters, because 'md5sum' tool lacks the ability of properly handling (hashing) files with whitespaces in filenames.