1
我已重命名的文件夹中的文件,但是当我尝试将文件移动到另一个位置,我收到一条错误消息 -如何刷新数据
文件未找到。
文件路径仍持有即c:\user\appFolder\OldFileName.txt
但该文件夹中的文件名称已更改为NewFileName.txt
你如何刷新数据旧文件名?下面
foreach (string filename in fileEntries)
{
RenameFile(filename);
string fileName = Path.GetFileName(filename);
string destinationPath = TransfersPath;
string sourceFile = System.IO.Path.Combine(sourcePath);
string destFile = System.IO.Path.Combine(destinationPath, fileName);
System.IO.File.Move(sourceFile, destFile);
}
你的代码没有多大意义。 'RenameFile'做了什么?为什么要循环访问'fileEntries',并且只对每个条目使用'fileName'作为同一个'sourcePath'的目的地?看起来像逻辑错误...... – Igor
当然,'fileName'不会改变为新名称。除了你之外没有人能改变它,而你却没有。 –
文件系统数据不需要刷新。当你调用任何文件操作时,文件系统就像在Windows资源管理器中看起来一样。问题可能与您的输入字符串File.Move() – spectacularbob