WindowsError: [Error 183] Cannot create a file when that file already exists

前端 未结 1 1954
猫巷女王i
猫巷女王i 2021-01-14 14:50

I am using the following script to add a copy right to all the files in the directories and subdirectories for a give directory passed as first argument ,am running the scri

1条回答
  •  广开言路
    2021-01-14 15:01

    If you want to append to an existing file, you need something like:

    with open(fullname, "ab") as in_file

    Q: Are you sure you can use shutil.copyfileobj(in_file, out_file) with an open out_file that you've already written to?

    Q: Do you know which line is causing the windows error?

    Thank you for the update.

    I'll bet your directory already has a file already named fullname, hence os.rename(temp_fname, fullname) fails with "file already exists".

    Q: Would shutil.move work instead?

    0 讨论(0)
提交回复
热议问题