using System; using System.Collections.Generic; using System.Text; using System.IO; namespace Dachie { class Program { static void Main(string[] args) { DirectoryCopy(@"C:\Users\Administrator\Desktop\EditGridviewCells", @"C:\Users\Administrator\Desktop\新建文件夹", true); Console.WriteLine("OK"); } /// <summary> /// 创建虚拟目录 /// </summary> /// <param name="sourceDirName">源文件目录名</param> /// <param name="destDirName">目标文件目录名</param> /// <param name="copySubDirs">是否拷贝子目录</param> internal static void DirectoryCopy( string sourceDirName, string destDirName, bool copySubDirs) { DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); // If the source directory does not exist, throw an exception. if (!dir.Exists) { throw new DirectoryNotFoundException( "Source directory does not exist or could not be found: " + sourceDirName); } // If the destination directory does not exist, create it. if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } // Get the file contents of the directory to copy. FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { // Create the path to the new copy of the file. string temppath = Path.Combine(destDirName, file.Name); // Copy the file. file.CopyTo(temppath, false); } // If copySubDirs is true, copy the subdirectories. if (copySubDirs) { foreach (DirectoryInfo subdir in dirs) { // Create the subdirectory. string temppath = Path.Combine(destDirName, subdir.Name); // Copy the subdirectories. DirectoryCopy(subdir.FullName, temppath, copySubDirs); } } } } }

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-10-24
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案