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