I want to display all the .txt files on my system. But when I execute my code I only get displayed the .txt files on my removable Disk Drive (USB-Stick).
How can I fix this?
Thank you for your help :D
Here's my code:
static List<string> Search()
{
var files = new List<string>();
foreach (DriveInfo d in DriveInfo.GetDrives().Where(x => x.IsReady))
{
try
{
files.AddRange(Directory.GetFiles(d.RootDirectory.FullName, "*.txt", SearchOption.AllDirectories));
Console.Write(string.Join(System.Environment.NewLine, files));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return files;
}
My console output:
The access to the path "C: \$ Recycling. Bin\S-1-5-18" was refused.
D:\Test\Test1.txt
D:\Test\Test2.txt
...
D:\PortableApps\EclipsePortable\Other\Source\Readme.txtSystem.Collections.Generic.List`1[System.String]
I don't get any error messages at all.