国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 荃湾区| 南皮县| 湖口县| 郴州市| 德兴市| 南丰县| 临洮县| 宜章县| 从江县| 闵行区| 贞丰县| 镇远县| 筠连县| 耒阳市| 广东省| 利津县| 新丰县| 军事| 平原县| 大同市| 扬州市| 都安| 城步| 甘肃省| 临沭县| 鄂伦春自治旗| 惠安县| 天镇县| 华安县| 日照市| 山东| 临沭县| 永安市| 荆州市| 若尔盖县| 南漳县| 赤壁市| 东山县| 神木县| 邵武市| 三门县|