using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Recursive_File_Name_Print_in_a_Folder_Structure
{
class Program
{
static void Main(string[] args)
{
// ENTER A PATH, For ex: C:\Temp
Console.WriteLine("Please enter a path name to get all files: ");
string path = Console.ReadLine();
FindFiles(path);
Console.ReadKey();
}
public static void FindFiles(string path)
{
foreach (string fileName in Directory.GetFiles(path))
{
Console.WriteLine(fileName);
}
foreach (string directory in Directory.GetDirectories(path))
{
// Notice that FindFiles() is calling itself
FindFiles(directory);
}
}
}
}
/* ANOTHER EXAMPLE, LETS GIVE IT A TRY...
static void DirSearch(string sDir)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
Console.WriteLine(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
*/