What 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:
- If the file doesn't exist at the destination location, successfully move the file, or;
- If the file does exist at the destination location, delete it, then move the file.
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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…