Reputation: 436
In Windows Explorer you can have this structure:
(a directory)
(a file without an extension)
My structure is:
(a directory)
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.
Upvotes: 0
Views: 100
Reputation: 613572
... 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.
Upvotes: 3