Moving files from one folder to another C#

Anoushka Seechurn picture Anoushka Seechurn · Oct 31, 2013 · Viewed 90.5k times · Source

Guys I am trying to move all files ending with _DONE into another folder.

I tried

 //take all files of main folder to folder model_RCCMrecTransfered 
            string rootFolderPath = @"F:/model_RCCMREC/";
            string destinationPath = @"F:/model_RCCMrecTransfered/";
            string filesToDelete = @"*_DONE.wav";   // Only delete WAV files ending by "_DONE" in their filenames
            string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
            foreach (string file in fileList)
            {
                string fileToMove = rootFolderPath + file;
                string moveTo = destinationPath + file;
                //moving file
                File.Move(fileToMove, moveTo);

But on executing these codes i get an error saying.

The given path's format is not supported.

Where did I go wrong ?

Answer

codemonkeh picture codemonkeh · Oct 31, 2013

Your slashes are in the wrong direction. On windows you should use back slashes. E.g.

string rootFolderPath = @"F:\model_RCCMREC\";
string destinationPath = @"F:\model_RCCMrecTransfered\";