Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving files from one folder to another C#

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 ?

like image 383
Anoushka Seechurn Avatar asked Oct 31 '13 06:10

Anoushka Seechurn


People also ask

How do I move files from one folder to another?

You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop. Folder Tree: Right-click the file or folder you want, and from the menu that displays click Move or Copy.

How do I move multiple files from one directory to another in C#?

First get all the files with specified extension using Directory. GetFiles() and then iterate through each files in the list and move them to target directory. Show activity on this post. will Move all the files from Desktop to Directory " TextFiles ".


1 Answers

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\"; 
like image 200
codemonkeh Avatar answered Sep 22 '22 09:09

codemonkeh