Home > Code > C# > How to copy all files from one folder to another folder using C#

How to copy all files from one folder to another folder using C#

by samba   on Jun 03, 2015   Category: C#   |  Views: 669    |  Points: 25   |  Starter 


using System.IO;

namespace ConsoleApplication3
{
public class SimpleFileCopy
{
static void Main()
{
string sourcePath = @"C:\Source\";
string targetPath = @"C:\Files\";

if (Directory.Exists(sourcePath))
{
DirectoryInfo dirinfo = new DirectoryInfo(sourcePath);
DirectoryInfo[] listofSubDir=dirinfo.GetDirectories();
foreach (var item in listofSubDir)
{
var childItem = item.FullName + "\\" + "C1";
string[] files = System.IO.Directory.GetFiles(childItem);
foreach (var file in files)
{
Console.WriteLine(file);

}


}

Console.Read();

}
}
}
}


Post Code  |  Code Snippet Home

User Responses


  Re :How to copy all files from one folder to another folder using C#   
Posted by Pavankhole00@gmail.com
on 25/06/2015
Points : 5

No effect with these code.when we run it, it run without any error...but nothing happen after that.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts