Why am I getting error, if my script creates a folder? I am using Python on Windows 7. The error:
FileExistsError: [WinError 183] Cannot create a file when that file already exists: [path to the file or folder in question]
The problem is that file and folder were not there.
Press Windows key + R to open up a Run dialog box. Then, type ms-settings:windowsupdate and press Enter to open up the Windows Update tab inside the Settings app. Run dialog: ms-settings:windowsupdate. Inside the Windows Update screen, click on Check for updates and install every available pending update.
183: Cannot create a new file when that file already exists. This is a generic Windows Services error that is returned when a service cannot be successfully started. There are a variety of possible situations that can prevent the Laserfiche Server service from successfully starting.
I just encountered this same issue. This thread helped me solve the problem, but the following clarification might help someone:
For me, the misunderstanding came from shutil.copytree(source, destination, symlinks, ignore)
.
I read destination
as being the place where my copied tree will go. In reality, it creates that location and then copies the tree there. So if your destination directory already exists, like mine did, you'll get the error.
Hope that helps someone.
As the comments point out, the folder already exists. You seem to think that attempts to create a folder that already exists should simply do nothing. But that is not how Windows sees it.
To avoid the error message, check first to see if the folder exists. Before the code that creates the folder, do
if not os.path.exists("name of folder"):
I just encountered a slightly more subtle version of this, this might help someone else.
I was creating a folder with:os.makedirs(os.path.dirname(my_filename), exist_ok=True)
Which should create the folder, but not error if it already exists. I'd run this numerous times with no problem.
Ran it again, and got an error:
FileExistsError: [WinError 183] Cannot create a file when that file already exists: '\my\folder\path'
Eventually worked out that I had kept the output folder from a previous run for comparison, by renaming it to something else.
Which shouldn't have caused a problem, but I still had one of the files from that folder open in Notepad. So since there was still an active reference to the folder the OS was throwing an error.
Closed the file in Notepad an re-ran, worked fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With