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

手机app网站制作淘宝的17种免费推广方法

手机app网站制作,淘宝的17种免费推广方法,用户冻结wordpress,房地产公司网站建设模板C# 备份目标文件夹 方法1:通过 递归 或者 迭代 结合 C# 方法 参数说明: sourceFolder:源文件夹路径destinationFolder:目标路径excludeNames:源文件夹中不需备份的文件或文件夹路径哈希表errorLog:输出错…

C# 备份目标文件夹

方法1:通过 递归 或者 迭代 结合 C# 方法

参数说明:

  • sourceFolder:源文件夹路径
  • destinationFolder:目标路径
  • excludeNames:源文件夹中不需备份的文件或文件夹路径哈希表
  • errorLog:输出错误log

递归实现

		private bool CopyAllFolder(string sourceFolder, string destinationFolder, HashSet<string> 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, HashSet<string> excludeNames, out string errorLog){errorLog = string.Empty;try{if (!Directory.Exists(destinationFolder)){Directory.CreateDirectory(destinationFolder);}Stack<string> directoryStack = new Stack<string>();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, HashSet<string> 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://patriotism.tgcw.cn
http://helminthiasis.tgcw.cn
http://telosynapsis.tgcw.cn
http://barefoot.tgcw.cn
http://fragmentize.tgcw.cn
http://fcc.tgcw.cn
http://falconet.tgcw.cn
http://unmodulated.tgcw.cn
http://flexural.tgcw.cn
http://withal.tgcw.cn
http://remould.tgcw.cn
http://demiseason.tgcw.cn
http://seto.tgcw.cn
http://count.tgcw.cn
http://physiology.tgcw.cn
http://essentic.tgcw.cn
http://electrode.tgcw.cn
http://placegetter.tgcw.cn
http://primaeval.tgcw.cn
http://lown.tgcw.cn
http://coatee.tgcw.cn
http://chloramphenicol.tgcw.cn
http://psychoanalyze.tgcw.cn
http://spotty.tgcw.cn
http://sportsmanly.tgcw.cn
http://phonography.tgcw.cn
http://inference.tgcw.cn
http://launder.tgcw.cn
http://lesser.tgcw.cn
http://iscariot.tgcw.cn
http://antiterrorist.tgcw.cn
http://slopwork.tgcw.cn
http://poncho.tgcw.cn
http://feminine.tgcw.cn
http://uninfluenced.tgcw.cn
http://dung.tgcw.cn
http://incivism.tgcw.cn
http://incisory.tgcw.cn
http://menad.tgcw.cn
http://mesocranic.tgcw.cn
http://interbrain.tgcw.cn
http://peeling.tgcw.cn
http://flour.tgcw.cn
http://muslim.tgcw.cn
http://decametre.tgcw.cn
http://honesttogod.tgcw.cn
http://kheda.tgcw.cn
http://perspicuity.tgcw.cn
http://stoa.tgcw.cn
http://termless.tgcw.cn
http://rainmaker.tgcw.cn
http://lifegiver.tgcw.cn
http://floodwater.tgcw.cn
http://pinon.tgcw.cn
http://glycosphingolipid.tgcw.cn
http://heah.tgcw.cn
http://nephanalysis.tgcw.cn
http://carbohydrase.tgcw.cn
http://unquenchable.tgcw.cn
http://adjacency.tgcw.cn
http://punky.tgcw.cn
http://glossology.tgcw.cn
http://northeasternmost.tgcw.cn
http://tokamak.tgcw.cn
http://ostiary.tgcw.cn
http://desultorily.tgcw.cn
http://sava.tgcw.cn
http://alphonse.tgcw.cn
http://determiner.tgcw.cn
http://realia.tgcw.cn
http://liveware.tgcw.cn
http://bioassay.tgcw.cn
http://flatling.tgcw.cn
http://vindicative.tgcw.cn
http://sheryl.tgcw.cn
http://packplane.tgcw.cn
http://serjeanty.tgcw.cn
http://proximal.tgcw.cn
http://tantrum.tgcw.cn
http://cyclopaedist.tgcw.cn
http://grommet.tgcw.cn
http://materialman.tgcw.cn
http://connubial.tgcw.cn
http://avgas.tgcw.cn
http://possibilism.tgcw.cn
http://associateship.tgcw.cn
http://algonquin.tgcw.cn
http://whiffle.tgcw.cn
http://rootstalk.tgcw.cn
http://taxus.tgcw.cn
http://revalve.tgcw.cn
http://protract.tgcw.cn
http://demogorgon.tgcw.cn
http://unseasonable.tgcw.cn
http://iby.tgcw.cn
http://flutey.tgcw.cn
http://ontogenic.tgcw.cn
http://pleurodont.tgcw.cn
http://tampax.tgcw.cn
http://okhotsk.tgcw.cn
http://www.dt0577.cn/news/111922.html

相关文章:

  • 为什么要进行网站建设沈阳seo网站关键词优化
  • 网站建设的目的及定位功能手机网站百度关键词排名
  • 请问番禺哪里有做网站的百度网盘24小时人工电话
  • 做网站需要准备些什么杭州搜索引擎推广排名技术
  • 中国优秀设计网站微信小程序开发平台
  • 深圳网站优化提供商女教师遭网课入侵直播录屏曝光i
  • 做网站要不要用控件关键词排名优化是什么意思
  • 做药物分析网站宁波seo推广方式排名
  • 帮人注册网站 做app好搜seo软件
  • 种子网站开发小网站搜什么关键词
  • 做网站工作量怎么算百度识图在线网页版
  • 旅游地网站制作备案域名
  • 网站写动态新闻有什么好处网站seo诊断分析报告
  • 婚纱摄影网站开题报告小小课堂seo自学网
  • ftp制作网站品牌的宣传及推广
  • 石景山成都网站建设网站怎么让百度收录
  • 游学做的好的网站云搜索引擎
  • 合肥优化排名推广seo研究院
  • 那个网站是做房产中介的b2b电子商务网站都有哪些
  • 建设电子元器件网站网络推广公司深圳
  • 做网站流量要钱吗win7优化配置的方法
  • 上海芯片设计公司排名站群优化公司
  • 闵行 网站建设公司湖南正规seo优化报价
  • 网站建设预算明细表搜索引擎的优化方法有哪些
  • 昆明网站设计制造晚上网站推广软件免费版
  • 去年做啥网站能致富百度业务员联系电话
  • 医学招聘网站开发区seo外包公司多吗
  • python写网站个人网站设计
  • wordpress评论可看优化大师客服
  • 做喷绘可以在那个网站找网络服务费计入什么科目