Reputation: 135
I have renamed a file within a folder, but when I try to move the file to another location I receive an error message -
File not found.
The file path still holds the old file name i.e. c:\user\appFolder\OldFileName.txt
But within the folder the file name has been changed to the NewFileName.txt
How do you refresh the data?
Code below
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);
}
Upvotes: 1
Views: 173
Reputation: 62290
It seems that calling method doesn't know the new filename.
So, You need to return new file name from RenameFile method
string newFilename = RenameFile(filename);
and use newFilename in the rest of the code instead of filename.
Upvotes: 2