Nếu bạn đang tìm code c# thực hiện copy thư mục thì đây, ngay bên dưới đây là code bạn cần nhé!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private void DirectoryCopy(string sourceDir, string destDir) { DirectoryInfo dir = new DirectoryInfo(sourceDir); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw new DirectoryNotFoundException( "Không tìm thấy thư mục: " + sourceDir); } if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { string temppath = Path.Combine(destDir, file.Name); file.CopyTo(temppath,true); } foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destDir, subdir.Name); DirectoryCopy(subdir.FullName, temppath); } } |
Trong đó:…
Xem thêm Copy folder in C#