当前位置: 首页 > news >正文

网站建设报价单 excel建设局官网查询系统

网站建设报价单 excel,建设局官网查询系统,高安做网站,做盗版影视网站违法吗C# 备份目标文件夹 方法1#xff1a;通过 递归 或者 迭代 结合 C# 方法 参数说明#xff1a; sourceFolder#xff1a;源文件夹路径destinationFolder#xff1a;目标路径excludeNames#xff1a;源文件夹中不需备份的文件或文件夹路径哈希表errorLog#xff1a;输出错…C# 备份目标文件夹 方法1通过 递归 或者 迭代 结合 C# 方法 参数说明 sourceFolder源文件夹路径destinationFolder目标路径excludeNames源文件夹中不需备份的文件或文件夹路径哈希表errorLog输出错误log 递归实现 private bool CopyAllFolder(string sourceFolder, string destinationFolder, HashSetstring excludeNames, out string errorLog){errorLog string.Empty;try{if (!Directory.Exists(destinationFolder)){Directory.CreateDirectory(destinationFolder);}string[] directories Directory.GetDirectories(sourceFolder);string[] files Directory.GetFiles(sourceFolder);foreach (string file in files){if (excludeNames.Count ! 0 excludeNames.Contains(file)){continue;}try{if (!BRTools.IsFileReady(file) || !BRTools.IsNotFileInUse(file, out errorLog)) // 检测文件是否被占用{return false;}string destinationFile Path.Combine(destinationFolder, Path.GetFileName(file));File.Copy(file, destinationFile, true);}catch (Exception ex){errorLog $Error copying file {file}: {ex.Message}\n;return false;}}foreach (string directory in directories){if (excludeNames.Count ! 0 excludeNames.Contains(directory)){continue;}string destinationSubFolder Path.Combine(destinationFolder, Path.GetFileName(directory));if (!CopyAllFolder(directory, destinationSubFolder, excludeNames, out string subfolderErrorLog)){errorLog subfolderErrorLog;return false;}}return true;}catch (Exception ex){errorLog $Error during folder copy: Message {ex.Message}, StackTrace {ex.StackTrace}\n;return false;}}迭代实现 private bool CopyAllFolder(string sourceFolder, string destinationFolder, HashSetstring excludeNames, out string errorLog){errorLog string.Empty;try{if (!Directory.Exists(destinationFolder)){Directory.CreateDirectory(destinationFolder);}Stackstring directoryStack new Stackstring();directoryStack.Push(sourceFolder);while (directoryStack.Count 0){string currentDirectory directoryStack.Pop();string[] directories Directory.GetDirectories(currentDirectory);string[] files Directory.GetFiles(currentDirectory);foreach (string file in files){if (excludeNames.Count ! 0 excludeNames.Contains(file)){continue;}try{if (!BRTools.IsFileReady(file) || !BRTools.IsNotFileInUse(file, out errorLog)){return false;}string destinationFile Path.Combine(destinationFolder, Path.GetFileName(file));File.Copy(file, destinationFile, true);}catch (Exception ex){errorLog $Error copying file {file}: {ex.Message}\n;return false;}}foreach (string directory in directories){if (excludeNames.Count ! 0 excludeNames.Contains(directory)){continue;}string destinationSubFolder Path.Combine(destinationFolder, Path.GetFileName(directory));if (!CopyAllFolder(directory, destinationSubFolder, excludeNames, out string subfolderErrorLog)){errorLog subfolderErrorLog;return false;}directoryStack.Push(directory);}}return true;}catch (Exception ex){errorLog $Error during folder copy: Message {ex.Message}, StackTrace {ex.StackTrace}\n;return false;}}方法2利用 Windows API [DllImport(shell32.dll, CharSet CharSet.Auto)]public static extern int SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);[StructLayout(LayoutKind.Sequential, CharSet CharSet.Auto)]public struct SHFILEOPSTRUCT{public IntPtr hwnd;public int wFunc;public string pFrom;public string pTo;public short fFlags;public bool fAnyOperationsAborted;public IntPtr hNameMappings;}const int FO_COPY 0x0002;const int FOF_NOCONFIRMATION 0x0010;const int FOF_SILENT 0x0004;const int FOF_NO_UI FOF_NOCONFIRMATION | FOF_SILENT;private bool CopyDirectory(string sourceDir, string destDir, out string errorLog){errorLog string.Empty;try{SHFILEOPSTRUCT fileOp new SHFILEOPSTRUCT();fileOp.wFunc FO_COPY;fileOp.pFrom sourceDir \0 \0; // Must end with double null characterfileOp.pTo destDir \0 \0; // Must end with double null character//fileOp.fFlags FOF_NO_UI;fileOp.fFlags FOF_NO_UI | FOF_NOCONFIRMATION; // 忽略UI和确认对话框int result SHFileOperation(ref fileOp);// 检查返回值if (result ! 0){errorLog $SHFileOperation failed with error code: {result};return false;}return true;}catch (Exception ex){errorLog $Failed to copy the entire folder {sourceDir}: Message {ex.Message}, StackTrace {ex.StackTrace}\n;return false;}}private bool CopyFolder(string sourceFolder, string destinationFolder, HashSetstring excludeNames, out string errorLog){errorLog string.Empty;try{if (!CopyDirectory(sourceFolder, destinationFolder, out errorLog)){this.logger.Warning($errorLog: {errorLog});return false;}if (excludeNames.Count ! 0){foreach (var item in excludeNames){var targetPath Path.Combine(destinationFolder, GetSonFolderPath(sourceFolder, item)); // 获取已备份路径下需排除的文件夹或文件路径if (Directory.Exists(item)){ DeleteDir(targetPath);}if(File.Exists(item)){DeleteDir(targetPath);}}}return true;}catch(Exception ex){errorLog $Error during folder copy, and exception is: Message {ex.Message}, StackTrace {ex.StackTrace}\n;return false;}}private string GetSonFolderPath(string folderPath, string targetPath){string result string.Empty;try{folderPath folderPath.TrimEnd(Path.DirectorySeparatorChar) Path.DirectorySeparatorChar;if (!isFilePath(targetPath)){targetPath targetPath.TrimEnd(Path.DirectorySeparatorChar) Path.DirectorySeparatorChar;}else{targetPath Path.GetDirectoryName(targetPath).TrimEnd(Path.DirectorySeparatorChar);}if (targetPath.StartsWith(folderPath, StringComparison.OrdinalIgnoreCase)){result targetPath.Substring(folderPath.Length);}}catch (Exception){result string.Empty;}return result;}private bool isFilePath(string targetPath){if (Path.HasExtension(targetPath) File.Exists(targetPath))return true;return false;}private void DeleteFile(string file){if (File.Exists(file)){FileInfo fi new FileInfo(file);if (fi.IsReadOnly){fi.IsReadOnly false;}File.Delete(file);}}private void DeleteDir(string dir){if (Directory.Exists(dir)){foreach (string childName in Directory.GetFileSystemEntries(dir)){if (File.Exists(childName)){FileInfo fi new FileInfo(childName);if (fi.IsReadOnly){fi.IsReadOnly false;}File.Delete(childName);}elseDeleteDir(childName);}Directory.Delete(dir, true);}}注意方法2有一个漏洞该方法无法成功捕捉到源文件夹下被占用的文件信息
http://www.w-s-a.com/news/759904/

相关文章:

  • phpstorm网站开发产品logo设计
  • 电子商务网站建设与运营什么是单页面网站
  • 西安优化网站公司南阳微信网站
  • 购物网站线下推广方案佛山快速建站哪家服务专业
  • 临沂网站排名外贸网站推广方法之一
  • 手机网站百度关键词排名查询吕梁网站制作吕梁安全
  • 做网站媒体wordpress管理员账号数据库添加
  • php如何自己做网站wordpress怎么修改编辑代码
  • 网站建网站建设公司WordPress互联
  • 泊头市网站建设价格wordpress导航菜单位置
  • 怎么设立网站赚广告费网页制作素材模板图片
  • 做班级网站的目的网站设计制作公司需要什么资质
  • 济南做网站哪家好财政网站平台建设不足
  • php网站建设招聘网站开发与设计论文
  • 上海 网站建设平台 补贴网站开发招标文件范本
  • 延安网站建设公司电话手机上那个网站做农产品推广比较好
  • 增城哪家网站建设好如何做网站实名认证
  • 常州地区做网站个人购物网站需要备案吗
  • 网站建设公司 跨界鱼科技专业做服务器的网站都有哪些
  • 欧洲网站服务器网站建设费用计入什么科目
  • 网站的色调苏州策划网站模板建站公司
  • 怎么看网站用的什么后台公路建设项目可行性研究报告编制办法哪个网站查最新版
  • 可以看的网站的浏览器有哪些专业APP客户端做网站
  • 如何做网站推广自己的产品推荐个网站好吗
  • 网站经营范围wordpress注入点
  • 学校网站开发协议夫妻网络网站建设
  • 福州网站seo推广优化微信商家小程序怎么弄
  • 免费网站推广工具在游戏网站做中介合法
  • 网站建设前的规划网站建设公司六安
  • 公司注册网站开发的行业表述南宁在百度上建网站