目录工具类 - C#小函数类推荐

server/2024/10/11 5:04:14/

       此文记录的是目录工具类。

/***目录工具类Austin Liu 刘恒辉Project Manager and Software DesignerE-Mail: lzhdim@163.comBlog:   http://lzhdim.cnblogs.comDate:   2024-01-15 15:18:00***/namespace Lzhdim.LPF.Utility
{using System.IO;/// <summary>/// The Object End of Directory/// </summary>public static class DirUtil{/// <summary>/// 复制指定目录到另一个目录(包括子目录和所有文件)/// </summary>/// <param name="sourceDir">源目录</param>/// <param name="targetDir">目标目录</param>/// <exception cref="DirectoryNotFoundException"></exception>public static void CopyDirectory(string sourceDir, string targetDir){DirectoryInfo dir = new DirectoryInfo(sourceDir);DirectoryInfo[] dirs = dir.GetDirectories();// If the source directory does not exist, throw an exception.if (!dir.Exists){throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDir}");}// If the destination directory does not exist, create it.if (!Directory.Exists(targetDir)){Directory.CreateDirectory(targetDir);}// Get the files in the directory and copy them to the new location.FileInfo[] files = dir.GetFiles();foreach (FileInfo file in files){string tempPath = Path.Combine(targetDir, file.Name);file.CopyTo(tempPath, false);}// If copying subdirectories, copy them and their contents to the new location.foreach (DirectoryInfo subdir in dirs){string tempPath = Path.Combine(targetDir, subdir.Name);CopyDirectory(subdir.FullName, tempPath);}}/// <summary>/// Create a dir/// </summary>/// <param name="dir">dir which need to create</param>/// <returns>true dir is create;false dir is create error</returns>public static bool CreateDir(string dir){if (!Directory.Exists(dir)){try{Directory.CreateDirectory(dir);return true;}catch{ }return false;}return true;}/// <summary>/// Delete a dir/// </summary>/// <param name="dir">dir which need to delete</param>/// <returns>true dir is delete;false dir is delete error</returns>public static bool DeleteDir(string dir){if (Directory.Exists(dir)){try{Directory.Delete(dir);return true;}catch{ }return false;}return false;}/// <summary>/// Check if dir is exist/// </summary>/// <param name="dir">dir which need to check</param>/// <returns>true dir is exist;false dir is not exist</returns>public static bool DirIsExist(string dir){return Directory.Exists(dir);}/// <summary>/// rename a dir/// </summary>/// <param name="srcDir">dir which need to rename</param>/// <param name="desDir">the renamed dir name</param>/// <returns>true rename is done;false rename is error</returns>public static bool RenameDir(string srcDir, string desDir){try{Directory.Move(srcDir, desDir);return true;}catch{ }return false;}}
}

http://www.ppmy.cn/server/129970.html

相关文章

基于SpringBoot+Vue的非物质文化遗产保护与传播系统设计实现【原创】(地图组件)

&#x1f388;系统亮点&#xff1a;地图组件&#xff1b; 一.系统开发工具与环境搭建 1.系统设计开发工具 后端使用Java编程语言的Spring boot框架 项目架构&#xff1a;B/S架构 运行环境&#xff1a;win10/win11、jdk17 前端&#xff1a; 技术&#xff1a;框架Vue.js&#x…

C++对C的扩展

目录 一、引言 二、C对C的扩展 1.面向对象 2.异常处理 3.模板 4.STL&#xff08;标准模板库&#xff09; 三、总结 本文将介绍C在C语言基础上的扩展&#xff0c;分析C在面向对象、异常处理、STL等方面的优势&#xff0c;帮助读者更好地理解C语言的特性及其在实际开发中的应用…

如何利用phpstudy创建mysql数据库

phpStudy诞生于2007年&#xff0c;是一款老牌知名的PHP开发集成环境工具&#xff0c;产品历经多次迭代升级&#xff0c;目前有phpStudy经典版、phpStudy V8&#xff08;2019版&#xff09;等等&#xff0c;利用phpstudy可以快速搭建一个mysql环境&#xff0c;接下来我们就开始吧…

架构与思维:漫谈高并发业务的CAS及ABA

1 高并发场景下的难题 1.1 典型支付场景 这是最经典的场景。支付过程&#xff0c;要先查询买家的账户余额&#xff0c;然后计算商品价格&#xff0c;最后对买家进行进行扣款&#xff0c;像这类的分布式操作&#xff0c;如果是并发量低的情况下完全没有问题的&#xff0c;但如果…

基于深度学习的3D人体姿态预测

基于深度学习的3D人体姿态预测是指利用深度学习模型&#xff0c;从图像或视频中自动估计人体的三维骨架结构或关节点位置。此任务在增强现实、动作捕捉、人体行为识别、虚拟现实等多个领域中有广泛应用。3D人体姿态预测面临的挑战包括姿态变化多样、遮挡、光照条件复杂以及不同…

vscode配置R语言debugger环境:“vscDebugger“的安装

要在 R 中安装 vscDebugger 包&#xff0c;可以按照以下步骤进行&#xff1a; 方法一&#xff1a;使用命令面板自动安装 打开命令面板&#xff1a; 在 Visual Studio Code 中按 CtrlShiftP 打开命令面板。 运行安装命令&#xff1a; 在命令面板中输入并选择 r.debugger.updat…

正则表达式应用场景与常用正则验证方法汇总

正则表达式&#xff08;RegEx&#xff09;用于匹配、搜索和处理字符串数据&#xff0c;常见应用场景包括&#xff1a; 应用场景&#xff1a; 数据验证&#xff1a;如邮箱、电话号码等格式验证。文本搜索与替换&#xff1a;批量替换或提取符合特定模式的文本。日志解析&#x…

彩族相机内存卡恢复多种攻略:告别数据丢失

在数字时代&#xff0c;相机内存卡作为我们存储珍贵照片和视频的重要媒介&#xff0c;其数据安全性显得尤为重要。然而&#xff0c;意外删除、错误格式化、存储卡损坏等情况时有发生&#xff0c;导致数据丢失&#xff0c;给用户带来不小的困扰。本文将详细介绍彩族相机内存卡数…