Last Updated: February 25, 2016
·
232
· Raxdiam Development

Simple recursive file scan

This may not be the most orthodox way to scan a directory, but it's useful for logging files throughout the scan.

using System.IO;

static void ScanDir(string dir)
{
    try
    {
        foreach (string d in Directory.GetDirectories(dir))
        {
            foreach (string file in Directory.GetFiles(d))
            {
                //Log each file path
                Console.WriteLine(file);
            }
            //Scan next directory
            ScanDir(d);
        }
    }
    catch (System.Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}