• asp.net复制整个文件夹


      /// <summary>
       /// 递归拷贝所有子目录。
       /// </summary>
       /// <param >源目录</param>
       /// <param >目的目录</param>
       public static void copyDirectory(string sPath, string dPath)
       {
           string[] directories = System.IO.Directory.GetDirectories(sPath);
           if (!System.IO.Directory.Exists(dPath))
               System.IO.Directory.CreateDirectory(dPath);
           System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sPath);
           System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
           CopyFile(dir, dPath);
           if (dirs.Length > 0)
           {
               foreach (System.IO.DirectoryInfo temDirectoryInfo in dirs)
               {
                   string sourceDirectoryFullName = temDirectoryInfo.FullName;
                   string destDirectoryFullName = sourceDirectoryFullName.Replace(sPath, dPath);
                   if (!System.IO.Directory.Exists(destDirectoryFullName))
                   {
                       System.IO.Directory.CreateDirectory(destDirectoryFullName);
                   }
                   CopyFile(temDirectoryInfo, destDirectoryFullName);
                   copyDirectory(sourceDirectoryFullName, destDirectoryFullName);
               }
           }
    
       }
    
       /// <summary>
       /// 拷贝目录下的所有文件到目的目录。
       /// </summary>
       /// <param >源路径</param>
       /// <param >目的路径</param>
       public static void CopyFile(System.IO.DirectoryInfo path, string desPath)
       {
           string sourcePath = path.FullName;
           System.IO.FileInfo[] files = path.GetFiles();
           foreach (System.IO.FileInfo file in files)
           {
               string sourceFileFullName = file.FullName;
               string destFileFullName = sourceFileFullName.Replace(sourcePath, desPath);
               file.CopyTo(destFileFullName, true);
           }
       }
  • 相关阅读:
    关于JavaScript文档对象
    关于JavaScript浏览器对象
    关于JavaScript事件与函数
    关于JavaScript基础知识
    关于CSS基础知识
    第七章:Hexadecimal, octal, ASCII, UTF8, Unicode, Runes
    没有 Cgroups,就没有 Docker
    Redis 文件事件
    Python 垃圾回收总结
    Docker Bridge 网络原理
  • 原文地址:https://www.cnblogs.com/njccqx/p/9672449.html
Copyright © 2020-2023  润新知