File Already Exists When Moving File

RareNCool

In Windows Explorer you can have this structure:

  • Main Directory
    • New Directory(a directory)
    • New Directory(a file without an extension)

My structure is:

  • Main Directory
    • New Directory(a directory)
    • Some File.txt

What I'm trying to do is rename "Some File.txt" to "New Directory", like you can in Explorer. I'm using File.Move("/Main Directory/Some File.txt", "/Main Directory/New Directory");

However, I keep getting an exception saying

Cannot create a file when that file already exists.

I assume it's not liking the fact that there's a directory named "New Directory". But given the fact that a directory and file with the same name may coexist, I don't see why the Move API fusses about this.

Is there some way to tell it to ignore directories with the same name when copying files, and vice versa?

EDIT: I recently reinstalled Windows and forgot to turn file extensions back on, so my rename in Explorer wasn't modifying the extension like I'm used to it doing. With extensions on, I can't perform the rename. So behavior is actually as expected. I'll leave this here in case someone does the same thing in the future.

David Heffernan

... given the fact that a directory and file with the same name may coexist ...

That statement is incorrect. Each object in a container must have a distinct name. Presumably your shell is configured to hide extensions of registered file types which is leading you to make this erroneous statement.

The error message reported is accurate and cannot be avoided without renaming one of the files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

FileZilla: Moving file into directory where file already exists fails with "failure"

From Dev

If File Already Exists Rename it

From Dev

Error in file already exists

From Dev

Cannot create a file when it already exists using File.Move

From Dev

mklink error: Cannot create a file when that file already exists

From Dev

Warning message if file name already exists when creating a pdf file

From Dev

Table already exists error when trying to import sql file

From Dev

This code is running well for upload and extension check but not when file already exists

From Dev

Open returns (-1) with O_CREAT when file already exists

From Dev

This code is running well for upload and extension check but not when file already exists

From Dev

Open returns (-1) with O_CREAT when file already exists

From Dev

Checking if destination file already exists

From Dev

Rename a file if same already exists

From Dev

Test to see if a file already exists

From Dev

Checking if destination file already exists

From Dev

Rename a file if same already exists

From Dev

No such file or directory when moving a file

From Dev

File.Copy() performance if a file already exists

From Dev

Renaming a file and appending a digit if a file already exists

From Dev

Renaming a file to name of file that already exists

From Dev

How to exit batch processing at beginning of a batch file when a file already exists?

From Dev

"Swap file xxx already exists" when editing apache configuration file in vim?

From Dev

Moving files only if matching file exists

From Dev

scp "no such file" when the file exists?

From Dev

How to copy-paste a file that already exists?

From Dev

Append text to text file if it already exists

From Dev

How to check if the file already exists in the LinkItemCollection?

From Dev

Ember-CLI error: file already exists

From Dev

Save with a different name if the file already exists in directory

Related Related

  1. 1

    FileZilla: Moving file into directory where file already exists fails with "failure"

  2. 2

    If File Already Exists Rename it

  3. 3

    Error in file already exists

  4. 4

    Cannot create a file when it already exists using File.Move

  5. 5

    mklink error: Cannot create a file when that file already exists

  6. 6

    Warning message if file name already exists when creating a pdf file

  7. 7

    Table already exists error when trying to import sql file

  8. 8

    This code is running well for upload and extension check but not when file already exists

  9. 9

    Open returns (-1) with O_CREAT when file already exists

  10. 10

    This code is running well for upload and extension check but not when file already exists

  11. 11

    Open returns (-1) with O_CREAT when file already exists

  12. 12

    Checking if destination file already exists

  13. 13

    Rename a file if same already exists

  14. 14

    Test to see if a file already exists

  15. 15

    Checking if destination file already exists

  16. 16

    Rename a file if same already exists

  17. 17

    No such file or directory when moving a file

  18. 18

    File.Copy() performance if a file already exists

  19. 19

    Renaming a file and appending a digit if a file already exists

  20. 20

    Renaming a file to name of file that already exists

  21. 21

    How to exit batch processing at beginning of a batch file when a file already exists?

  22. 22

    "Swap file xxx already exists" when editing apache configuration file in vim?

  23. 23

    Moving files only if matching file exists

  24. 24

    scp "no such file" when the file exists?

  25. 25

    How to copy-paste a file that already exists?

  26. 26

    Append text to text file if it already exists

  27. 27

    How to check if the file already exists in the LinkItemCollection?

  28. 28

    Ember-CLI error: file already exists

  29. 29

    Save with a different name if the file already exists in directory

HotTag

Archive