In python, I created a function to make a directory if it does not already exist.
def make_directory_if_not_exists(path): try: os.makedirs(path) break except OSError as exception: if exception.errno != errno.EEXIST: raise
On Windows, the following exception sometimes occurs:
WindowsError: [Error 5] Access is denied: 'C:\\...\\my_path'
It seems that when the directory is open in Windows File Browser, but I can not reliably play it. So instead, I made the following workaround.
def make_directory_if_not_exists(path): while not os.path.isdir(path): try: os.makedirs(path) break except OSError as exception: if exception.errno != errno.EEXIST: raise except WindowsError: print "got WindowsError" pass
What happens here, i.e. when does windows mkdir give such an access error? Is there a better solution?
python windows
izak
source share