2
我需要從目錄中獲取按名稱排序的文件列表。從目錄獲取按名稱排序的文件列表
我的文件被命名爲:
TestFile_1.xml,
TestFile_2.xml
TestFile_3.xml
.
.
TestFile_10.xml
TestFile_11.xml
我使用下面的代碼片段與此snnipet排序
DirectoryInfo di = new DirectoryInfo(jsonFileInfo.FolderPath);
FileSystemInfo[] files = di.GetFileSystemInfos();
var orderedFiles = files.OrderBy(f => f.Name);`
,我得到的結果
TestFile_1.xml,
TestFile_10.xml
TestFile_11.xml
.
.
TestFile_2.xml
TestFile_3.xml
.
.
我如何把它分類?
已經工作。否則,您應該澄清要求。名稱是一個字符串,字符串不知道「10」比「2」大。 – 2014-10-01 14:52:16
簡單的解決方案:命名文件'TestFile_01'而不是'TestFile_1' – DavidG 2014-10-01 14:52:54
我無法將文件從'TestFile_1'重命名爲'TestFile_01'。文件名將始終保持爲「TestFile1」 – Sameer 2014-10-01 14:55:19