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 26 27 28 29 30 31 32 33 34 35 |
DirectoryInfo sourcedinfo = new DirectoryInfo(@”D:\FromImage”); DirectoryInfo Destination = new DirectoryInfo(@”D:\ToImage”); public void CopyFile(DirectoryInfo source, DirectoryInfo target) { try { //check if the target directory exists if (Directory.Exists(target.FullName) == false) { Directory.CreateDirectory(target.FullName); } //copy all the files into the new directory foreach (FileInfo fi in source.GetFiles()) { fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true); } //copy all the sub directories using recursion foreach (DirectoryInfo diSourceDir in source.GetDirectories()) { DirectoryInfo nextTargetDir = target.CreateSubdirectory(diSourceDir.Name); CopyFile(diSourceDir, nextTargetDir); } MessageBox.Show(“Copy Successfully”, “Confirmation”); } catch (IOException ie) { MessageBox.Show(ie.Message); } } |
Thank you for reading Create File Copier with C#.
Leave a Comment