本文介绍了File.Move 不起作用 - 文件已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件夹:
c:est
我正在尝试此代码:
File.Move(@"c: estSomeFile.txt", @"c: estTest");
我得到异常:
文件已存在
输出目录肯定存在,输入文件在那里.
The output directory definitely exists and the input file is there.
推荐答案
您需要将其移动到另一个文件(而不是文件夹),这也可以用于重命名.
You need to move it to another file (rather than a folder), this can also be used to rename.
移动:
File.Move(@"c: estSomeFile.txt", @"c: estTestSomeFile.txt");
重命名:
File.Move(@"c: estSomeFile.txt", @"c: estSomeFile2.txt");
在你的例子中它说文件已经存在"的原因是因为 C:estTest
试图创建一个没有扩展名的文件 Test
,但不能这样做是因为已存在同名文件夹.
The reason it says "File already exists" in your example, is because C:estTest
tries to create a file Test
without an extension, but cannot do so as a folder already exists with the same name.
这篇关于File.Move 不起作用 - 文件已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!