国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

C#文件及文件夾復制,移動,刪除

2019-11-17 03:13:29
字體:
來源:轉載
供稿:網(wǎng)友

C#文件及文件夾復制,移動,刪除

classFile_DirManipulate{/// <summary>///FileCopy/// </summary>/// <param name="srcFilePath">源路徑</param>/// <param name="destFilePath">目標路徑</param>public static void FileCopy(string srcFilePath,string destFilePath){File.Copy(srcFilePath, destFilePath);}/// <summary>///FileMove/// </summary>/// <param name="srcFilePath">源路徑</param>/// <param name="destFilePath">目標路徑</param>public static void FileMove(string srcFilePath, string destFilePath){File.Move(srcFilePath, destFilePath);}/// <summary>///FileDelete/// </summary>/// <param name="delFilePath"></param>public static void FileDelete(string delFilePath){File.Delete(delFilePath);}/// <summary>///刪除文件夾及文件夾中的內容/// </summary>/// <param name="delFolderPath"></param>public static void FolderDelete(string delFolderPath){if (delFolderPath[delFolderPath.Length - 1] != Path.DirectorySeparatorChar)delFolderPath += Path.DirectorySeparatorChar;//string[] fileList = Directory.GetFileSystemEntries(delFolderPath);

foreach (string item in Directory.GetFileSystemEntries(delFolderPath)){if (File.Exists(item)){FileInfo fi = new FileInfo(item);if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)//改變只讀文件屬性,否則刪不掉fi.Attributes = FileAttributes.Normal;File.Delete(item);}//刪除其中的文件elseFolderDelete(item);//遞歸刪除子文件夾}Directory.Delete(delFolderPath);//刪除已空文件夾

}/// <summary>///文件夾拷貝/// </summary>/// <param name="srcFolderPath"></param>/// <param name="destFolderPath"></param>public static void FolderCopy(string srcFolderPath, string destFolderPath){//檢查目標目錄是否以目標分隔符結束,如果不是則添加之if (destFolderPath[destFolderPath.Length - 1] != Path.DirectorySeparatorChar)destFolderPath += Path.DirectorySeparatorChar;//判斷目標目錄是否存在,如果不在則創(chuàng)建之if (!Directory.Exists(destFolderPath))Directory.CreateDirectory(destFolderPath);string[] fileList = Directory.GetFileSystemEntries(srcFolderPath);foreach (string file in fileList){if (Directory.Exists(file))FolderCopy(file, destFolderPath + Path.GetFileName(file));else{FileInfo fi = new FileInfo(file);if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)//改變只讀文件屬性,否則刪不掉fi.Attributes = FileAttributes.Normal;try{ File.Copy(file, destFolderPath + Path.GetFileName(file), true); }catch (Exception e){}}}}/// <summary>///文件夾移動/// </summary>/// <param name="srcFolderPath"></param>/// <param name="destFolderPath"></param>public static void FolderMove(string srcFolderPath, string destFolderPath){//檢查目標目錄是否以目標分隔符結束,如果不是則添加之if (destFolderPath[destFolderPath.Length - 1] != Path.DirectorySeparatorChar)destFolderPath += Path.DirectorySeparatorChar;//判斷目標目錄是否存在,如果不在則創(chuàng)建之if (!Directory.Exists(destFolderPath))Directory.CreateDirectory(destFolderPath);string[] fileList = Directory.GetFileSystemEntries(srcFolderPath);foreach (string file in fileList){if (Directory.Exists(file)){FolderMove(file, destFolderPath + Path.GetFileName(file));//Directory.Delete(file);}elseFile.Move(file, destFolderPath + Path.GetFileName(file));}Directory.Delete(srcFolderPath);}}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 离岛区| 兴海县| 马边| 荥经县| 察哈| 惠州市| 九龙县| 衡阳县| 迁西县| 景洪市| 台州市| 宜城市| 裕民县| 漠河县| 景德镇市| 思茅市| 镇康县| 都江堰市| 天全县| 常山县| 仁布县| 四平市| 黔东| 武胜县| 长宁区| 米林县| 彩票| 财经| 绿春县| 陆丰市| 阜南县| 汝城县| 独山县| 三原县| 平原县| 梁山县| 巴马| 金华市| 东方市| 文水县| 龙岩市|