I've got a folder:
c:est
I'm trying this code:
File.Move(@"c:estSomeFile.txt", @"c:estTest");
I get exception:
File already exists
The output directory definitely exists and the input file is there.
See Question&Answers more detail:osI've got a folder:
c:est
I'm trying this code:
File.Move(@"c:estSomeFile.txt", @"c:estTest");
I get exception:
File already exists
The output directory definitely exists and the input file is there.
See Question&Answers more detail:osWhat you need is:
if (!File.Exists(@"c:estTestSomeFile.txt")) {
File.Move(@"c:estSomeFile.txt", @"c:estTestSomeFile.txt");
}
or
if (File.Exists(@"c:estTestSomeFile.txt")) {
File.Delete(@"c:estTestSomeFile.txt");
}
File.Move(@"c:estSomeFile.txt", @"c:estTestSomeFile.txt");
This will either:
Edit: I should clarify my answer, even though it's the most upvoted!
The second parameter of File.Move should be the destination file - not a folder. You are specifying the second parameter as the destination folder, not the destination filename - which is what File.Move requires.
So, your second parameter should be c:estTestSomeFile.txt
.