from: http://blog.logiclabz.com/c/copy-directory-in-net-c-including-sub-folders.aspx

  1. System.IO  


  1. private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)  
  2.        {  
  3.            bool ret = false;  
  4.            try  
  5.            {  
  6.                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";  
  7.                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";  
  8.   
  9.                if (Directory.Exists(SourcePath))  
  10.                {  
  11.                    if (Directory.Exists(DestinationPath) == false)  
  12.                        Directory.CreateDirectory(DestinationPath);  
  13.   
  14.                    foreach (string fls in Directory.GetFiles(SourcePath))  
  15.                    {  
  16.                        FileInfo flinfo = new FileInfo(fls);  
  17.                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);  
  18.                    }  
  19.                    foreach (string drs in Directory.GetDirectories(SourcePath))  
  20.                    {  
  21.                        DirectoryInfo drinfo = new DirectoryInfo(drs);  
  22.                        if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)  
  23.                            ret = false;  
  24.                    }  
  25.                }  
  26.                ret = true;  
  27.            }  
  28.            catch (Exception ex)  
  29.            {  
  30.                ret = false;  
  31.            }  
  32.            return ret;  
  33.        } 


Using this function

  1. bool copy = CopyDirectory("c:\\temp\\index\\", "c:\\temp\\newindex\\", true); 

Posted by 세모아
,