File Sorter : FileInfo « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;
using System.ComponentModel;

    class FileSorter{
        static void SortAndShowFiles(string title,Comparison<FileInfo> sortOrder){
            FileInfo[] files = new DirectoryInfo("C:\\").GetFiles();
            Array.Sort(files, sortOrder);
            Console.WriteLine(title);
            foreach (FileInfo file in files){
                Console.WriteLine("  {0} ({1} bytes)",file.Name, file.Length);
            }
        }
        static void Main(){
            SortAndShowFiles("Sorted by name:",delegate(FileInfo first, FileInfo second)
                { return first.Name.CompareTo(second.Name); }
            );
        }
    }








15.13.FileInfo
15.13.1.Open an existing file and return a FileStream
15.13.2.Create StreamWriter from FileInfo
15.13.3.Create FileStream from FileInfo for writing
15.13.4.Create FileStream from FileInfo for reading
15.13.5.File Sorter
15.13.6.Show info on image types