Jul 09
Sadly there is no built-in function in System.IO that will copy a folder and its contents. Following is a simple recursive algorithm that copies a folder, its sub-folders and files, creating the destination folder if needed. For simplicity, there is no error handling; an exception will throw if anything goes wrong, such as null or invalid paths or if the destination files already exist.
using System; using System.IO; namespace CSharp411 { class Program { static void Main( string[] args ) { CopyFolder( @"C:\temp\test", @"C:\temp\out" ); Console.ReadLine(); } static public void CopyFolder( string sourceFolder, string destFolder ) { if (!Directory.Exists( destFolder )) Directory.CreateDirectory( destFolder ); string[] files = Directory.GetFiles( sourceFolder ); foreach (string file in files) { string name = Path.GetFileName( file ); string dest = Path.Combine( destFolder, name ); File.Copy( file, dest ); } string[] folders = Directory.GetDirectories( sourceFolder ); foreach (string folder in folders) { string name = Path.GetFileName( folder ); string dest = Path.Combine( destFolder, name ); CopyFolder( folder, dest ); } } } }
Copyright © 2007-8 Tiwebb Ltd. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without explicit permission from Tiwebb Ltd.


That helps too much.
Thank you
thanks, it was very helpful, i was wondering if it works as a windows application