from: http://blog.logiclabz.com/c/copy-directory-in-net-c-including-sub-folders.aspx
- System.IO
- private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
- {
- bool ret = false;
- try
- {
- SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
- DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
- if (Directory.Exists(SourcePath))
- {
- if (Directory.Exists(DestinationPath) == false)
- Directory.CreateDirectory(DestinationPath);
- foreach (string fls in Directory.GetFiles(SourcePath))
- {
- FileInfo flinfo = new FileInfo(fls);
- flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
- }
- foreach (string drs in Directory.GetDirectories(SourcePath))
- {
- DirectoryInfo drinfo = new DirectoryInfo(drs);
- if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
- ret = false;
- }
- }
- ret = true;
- }
- catch (Exception ex)
- {
- ret = false;
- }
- return ret;
- }
Using this function
- bool copy = CopyDirectory("c:\\temp\\index\\", "c:\\temp\\newindex\\", true);
'Programming' 카테고리의 다른 글
[펌] OOP 매직- private 멤버 억세스하기~ (0) | 2011.11.03 |
---|---|
[펌] 핸들 릭 찾기(핸들 누수 찾기) (0) | 2011.10.04 |
[펌] 왜 이리 버그가 많아요? (0) | 2011.08.23 |