aimPath)
{
    try
    {
        
// 检查目标目录是否以目录分割字符结束如果不是则添加之
        if (aimPath[aimPath.Length - 1!= Path.DirectorySeparatorChar)
        {
            aimPath 
+= Path.DirectorySeparatorChar;
        }
        
// 判断目标目录是否存在如果不存在则新建之
        if (Directory.Exists(aimPath))
        {
            
this.DeleteFolder(aimPath.Substring(0, aimPath.Length - 1));
        }
        Directory.CreateDirectory(aimPath);
        
//如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
        string[] fileList = Directory.GetFileSystemEntries(srcPath);
        
//遍历所有的文件和目录
        foreach (string file in fileList)
        {
            
//先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
            if (Directory.Exists(file))
                CopyDir(file, aimPath 
+ Path.GetFileName(file));
            
//否则直接Copy文件
            else
                File.Copy(file, aimPath 
+ Path.GetFileName(file), true);
        }
    }
    
catch (Exception ee)
    {
        
throw new Exception(ee.ToString());
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案