Best way to copy the entire contents of a directory in C#

http://stackoverflow.com/questions/58744/best-way-to-copy-the-entire-contents-of-a-directory-in-c

//Now Create all of the directories

foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",

SearchOption.AllDirectories))

Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));

//Copy all the files

foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",

SearchOption.AllDirectories))

File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s