I have some code to rename a whole bunch of files and move them to a new directory using os.rename(). Its fairly simple, nothing flashy. It worked until I had some overlap in batches and there were duplicate files, this raised a WindowsError. Since the code worked in all otherways, I did
try:
os.rename(...)
except WindowsError:
print "Duplicate file {}".format(fileName)
This worked fine, except that it implies that all WindowsErrors are from duplicate files. The result was that when another aspect of my script broke, it failed essentially silently.
How can I employ try...except to catch only specific exceptions? If its not possible, what workarounds exist?
catch WindowsError as e:and look atstr(e), anddir(e)