I'm building a script that renames some files to determine if the file is locked or not. The script does the following on every file in a given directory recursively.
try:
os.rename(source, temp)
os.rename(temp, source)
except OSError as e:
print 'exception'
My question is should there be a time.sleep(1) between the os.rename() calls? I'm worried the file might not be renamed by the time the other os.rename() call takes place, but I want it to run as fast as possible.
Thanks for any help.