zoukankan      html  css  js  c++  java
  • C#拷贝整个文件夹以及子目录和其中文件

       private void CopyDirectory(string srcPath, string desPath)

            {
                string folderName = srcdir.Substring(srcdir.LastIndexOf("\")+1);
     
                string desfolderdir = desPath +"\"+ folderName;
     
                if (desdir.LastIndexOf("\") == (desPath.Length - 1))
                {
                    desfolderdir = desPath + folderName;
                }
                string[] filenames = Directory.GetFileSystemEntries(srcPath);
     
                foreach (string file in filenames)
                {
                    if (Directory.Exists(file))
                    {
     
                        string currentdir = desfolderdir + "\" + file.Substring(file.LastIndexOf("\") + 1);
                        if (!Directory.Exists(currentdir))
                        {
                            Directory.CreateDirectory(currentdir);
                        }
     
                        CopyDirectory(file, desfolderdir);
                    }
     
                    else 
                    {
                        string srcfileName = file.Substring(file.LastIndexOf("\")+1);
     
                        srcfileName = desfolderdir + "\" + srcfileName;
     
     
                        if (!Directory.Exists(desfolderdir))
                        {
                            Directory.CreateDirectory(desfolderdir);
                        }
                         
                         
                        File.Copy(file, srcfileName);
                    }
                }
           }
  • 相关阅读:
    lLinux 下 Stress 压力测试工具
    zabbix 微信告警配置
    spark Intellij IDEA开发环境搭建
    Spark调优与调试
    在centos 6.5 x64中安装 spark-1.5.1
    二叉树的各种遍历算法
    ServletResponse的一些知识点
    UVA 10303 How Many Trees? (catlan)
    UVA 10183 How Many Fibs?
    UVA 10471 Gift Exchanging
  • 原文地址:https://www.cnblogs.com/LCLBook/p/10997206.html
Copyright © 2011-2022 走看看