class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
GetFiles("E:/");
GetSubFolders("E:/");
Console.Read();
}
static void GetFiles(string directory)
{
try
{
string [] files = Directory.GetFiles(directory);
Console.WriteLine("Files in folder \"{0}\"", directory);
foreach(string f in files)
{
Console.WriteLine(f);
}
}
catch(System.UnauthorizedAccessException)
{
Console.WriteLine("Access not allowed to \"{0}\"", directory);
}
}
static void GetSubFolders(string directory)
{
try
{
//Get files for this folder
GetFiles(directory);
string [] subFolders = Directory.GetDirectories(directory);
foreach(string sf in subFolders)
{
GetSubFolders(sf);
}
}
catch(System.UnauthorizedAccessException)
{
Console.WriteLine("Access not allowed to \"{0}\"", directory);
}
}
}