Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Renaming a File

Guys I am trying to remane a file (adding _DONE to its name)

my researches showed that File.move(OLDNAME,NEWNAME) is what I needed. Thus, I did,

try
{
    string oldname = name;
    //XYZ_ZXX_ZZZ
    string newName = ToBeTested + "_DONE.wav";
    //rename file
    //NOTE : OldName is already in format XYZ_III_SSS.wav
    File.Move(oldname, newName);

}
catch (Exception exRename)
{
    string ex1 = exRename.ToString();
    //logging an error 
    string m = "File renaming process failed.[" + ex1 + "]";
    CreateLogFile(p, m);
}

But It does not bears any result (File is not renamed) but the exception is logged.

as such

System.IO.FileNotFoundException: Could not find file 'C:\Users\Yachna\documents\visual studio 2010\Projects\FolderMonitoringService_RCCM\FolderMonitoringService_RCCM\bin\Debug\54447874_59862356_10292013_153921_555_877_400_101.wav'.
File name: 'C:\Users\Yachna\documents\visual studio 2010\Projects\FolderMonitoringService_RCCM\FolderMonitoringService_RCCM\bin\Debug\54447874_59862356_10292013_153921_555_877_400_101.wav'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at RCCMFolderMonitor.Monitor.OnChanged(Object source, FileSystemEventArgs e) in C:\Users\Yachna\documents\visual studio 2010\Projects\FolderMonitoringService_RCCM\RCCMFolderMonitor\Monitor.cs:line 209]

What did i do wrong ?

Answer*

Cancel
0