So how can i recursively search a Folder and un-hide ALL files and sub folders in a directory? Like have it check each file and each folder... if they're hidden.. un-hide them. Iv been messing around with it all morning with no luck... i got all folders to set back to normal but thats about it.
foreach (var filePath in Directory.GetFiles(@"C:\Temp2"))
{
Console.Write("File " + filePath);
FileAttributes fileAttribute = File.GetAttributes(filePath);
if ((fileAttribute & FileAttributes.Hidden) > 0)
{
Console.WriteLine(" is hidden.");
// unset the hidden flag, but do not change other flags:
File.SetAttributes(filePath, fileAttribute & ~FileAttributes.Hidden);
}
else
{
Console.WriteLine(" is not hidden.");
}
}
to do it recursively, use
Directory.GetFiles(@"C:\Temp2", "*", SearchOption.AllDirectories)
to include directories too, use GetFileSystemEntries
Directory.GetFileSystemEntries(@"C:\Temp2", "*", SearchOption.AllDirectories)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With