2.5.28 #
解答 #
官方解答:https://algs4.cs.princeton.edu/25applications/FileSorter.java.html
先获得目录里的所有文件名,然后排序输出即可。
代码 #
var directoryName = Console.ReadLine();
if (!Directory.Exists(directoryName))
{
Console.WriteLine(directoryName + " doesn't exist or isn't a directory");
return;
}
var directoryFiles = Directory.GetFiles(directoryName);
Array.Sort(directoryFiles);
for (var i = 0; i < directoryFiles.Length; i++)
Console.WriteLine(directoryFiles[i]);