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

首頁 > 編程 > C# > 正文

C#實現(xiàn)保存文件時重名自動生成新文件的方法

2020-01-24 01:35:15
字體:
供稿:網(wǎng)友

本文實例講述了C#實現(xiàn)保存文件時重名自動生成新文件的方法。分享給大家供大家參考。具體如下:

將一個文檔保存為 a.txt 時,發(fā)現(xiàn)此文件已經(jīng)存在,則自動保存為 a(1).txt

/// <summary>/// Generates a new path for duplicate filenames./// </summary>/// <param name="path">The path.</param>/// <returns></returns>private string GetNewPathForDupes( string path ){  string directory = Path.GetDirectoryName( path );  string filename = Path.GetFileNameWithoutExtension( path );  string extension = Path.GetExtension( path );  int counter = 1;  string newFullPath;  do  {  string newFilename = "{0}({1}).{2}".FormatWith( filename, counter, extension );  newFullPath = Path.Combine( directory, newFilename );  counter++;  } while ( System.IO.File.Exists( newFullPath ) );  return newFullPath;}

希望本文所述對大家的C#程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿图什市| 神木县| 衡山县| 宣化县| 正阳县| 宁都县| 新竹市| 皮山县| 墨玉县| 白朗县| 柯坪县| 安泽县| 阜平县| 西城区| 六枝特区| 台北市| 从化市| 宝清县| 大邑县| 会理县| 那曲县| 全椒县| 平昌县| 盈江县| 车致| 错那县| 玉龙| 邮箱| 叙永县| 毕节市| 连州市| 六枝特区| 隆昌县| 宁安市| 江华| 南溪县| 外汇| 扬州市| 福州市| 邹城市| 秀山|