Moving files from one folder to another
This article explain about how to Moving files from one folder to another with the code snippet in simple way.
The following c# code shows how to move all the files in one folder to another. The program can be customized to move selected files too
DirectoryInfo dir1= new DirectoryInfo("F:Folder1");
DirectoryInfo dir2 = new DirectoryInfo("F:Folder2");
FileInfo[] Folder1Files = dir1.GetFiles();
if(Folder1Files.Length > 0)
{
foreach(FileInfo aFile in Folder1Files)
{
if(File.Exists("F:Folder2" + aFile.Name))
{
File.Delete("F:Folder2" + aFile.Name);
}
aFile.MoveTo("F:Folder2" + aFile.Name);
}
}
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you
Regards,
Kapil