zoukankan      html  css  js  c++  java
  • 拷贝整个文件夹内容

    微软提供的System.IO.Directory不提供拷贝整个文件夹内容到其他目录的方法,所以自己写了一个

     

     1 
     2  public class SKDirectory
     3         {
     4             static public void CopyTo(string sourceDirName, string destDirName)
     5             {
     6                 if (!System.IO.Directory.Exists(sourceDirName))
     7                     throw new System.IO.DirectoryNotFoundException("Source Directory : " + sourceDirName + " Not Found.");
     8 
     9                 if (!System.IO.Directory.Exists(destDirName))
    10                     throw new System.IO.DirectoryNotFoundException("Dest Directory : " + destDirName + " Not Found.");
    11 
    12                 if (sourceDirName.Length != sourceDirName.Replace(destDirName, string.Empty).Length)
    13                     throw new Exception("Dest Directory Not Allowed.");
    14 
    15                 System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sourceDirName);
    16                 destDirName += "\\" + di.Name;
    17                 System.IO.Directory.CreateDirectory(destDirName);
    18 
    19                 foreach (System.IO.DirectoryInfo cdi in di.GetDirectories())
    20                     CopyTo(cdi.FullName, destDirName);
    21 
    22                 foreach (System.IO.FileInfo fi in di.GetFiles())
    23                     fi.CopyTo(destDirName + "\\" + fi.Name);
    24             }
    25         }
    26 
  • 相关阅读:
    树莓派 官方800万摄像头 参数
    51单片机 小车 L298N pwm调速 串口控制 按键控制
    51单片机 HC05蓝牙模块
    python 类属性和实例属性、方法 访问权限问题
    python 通过setup.py安装和卸载python软件包
    win10家庭版安装
    python 测试用例
    python 异常类型
    抽象工厂模式
    (转)UML类图与类的关系详解
  • 原文地址:https://www.cnblogs.com/sskset/p/563478.html
Copyright © 2011-2022 走看看