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); }
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。