@Shervan360, Welcome to Microsoft Q&A, based on my test, I reproduced your problem. The error often means that the program does not have the permission to access the file. You could try to use the following code to ignore the Inaccessible files.
var options = new EnumerationOptions
{
IgnoreInaccessible = true,
RecurseSubdirectories = true,
};
foreach (string file in Directory.EnumerateFiles("C:\\", "*.*", options))
{
Console.WriteLine( file);
}
Hope my code could help you. Best Regards, Jack
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.