Home   Cover Cover Cover Cover
 

Sorted directory

/csbook/solutions/18/A05.cs
using System;
using System.IO;

class FilesInDir {
  
  // Outputs the files on the directory arg[0] in descending order
  static void Main(string[] arg) {
    string dir = Directory.GetCurrentDirectory();
    if (arg.Length > 0) dir = arg[0];
    string[] file = Directory.GetFiles(dir);
    Array.Sort(file);
    Array.Reverse(file);
    foreach (string fn in file) Console.WriteLine(fn);
  }
}