zoukankan      html  css  js  c++  java
  • C# 1.将整个文件夹复制到目标文件夹中 2.将指定文件复制到指定目标文件夹中

                this.gs_reportTemplate.Gallery.Groups[0].Items.Clear();
                string filePath = Application.StartupPath;
                string sourcePath = Path.Combine(filePath, "reports");
                string sourcePathXml = Path.Combine(sourcePath, "XuHang");
                string targetPath = ReportTemplate.ReportTemplateDirectory;          
                CopyDir(sourcePath, targetPath);
     /// <summary>
            /// 将整个文件夹复制到目标文件夹中。
            /// </summary>
            /// <param name="srcPath">源文件夹</param>
            /// <param name="aimPath">目标文件夹</param>
            /// <returns></returns>
            public static void CopyDir(string srcPath, string aimPath)
            {
                // 检查目标目录是否以目录分割字符结束如果不是则添加之
                if (aimPath[aimPath.Length - 1] != Path.DirectorySeparatorChar)
                    aimPath += Path.DirectorySeparatorChar;
    
                // 判断目标目录是否存在如果不存在则新建之
                if (!Directory.Exists(aimPath))
                    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);
                    }
                }
            }
     /// 从一个目录文件将其内容移动到另一目录
            private void MoveFileTo()
            {
                string basePath = Application.StartupPath;
                string sourcePath = Path.Combine(basePath, "XuHangReports.dll");
                string targetTempPath = ReportTemplate.ReportTemplateDirectory;
                string targetPath = Path.Combine(targetTempPath, "XuHang", "XuHangReports.dll");
                File.Copy(sourcePath, targetPath, true);
            }
  • 相关阅读:
    ORA-01207: file is more recent than control file
    ORA-08189
    oracle 修改表空间存储路径
    oracle 日志文件管理
    Oracle ClusterwarePRCT-1011 : Failed to run "oifcfg".&nb
    linux:文件打包与压缩
    linux:查找搜索文件
    Python:lambda表达式(匿名函数)
    网络协议各层概述
    linux:用户及文件权限管理
  • 原文地址:https://www.cnblogs.com/lqsilly/p/3196330.html
Copyright © 2011-2022 走看看