Hello friends,
foreach (FileInfo fi in new DirectoryInfo(filePath).GetFiles("*.*", SearchOption.AllDirectories))
{
}
I am using above code to get all files in selected path, if i select E:\ then "System Volume Information" folder will not be accessible and foreach will throw exception and its come out of loop. not getting other folder/files.
please suggest how can we get all files/folder except special folder???
Thanks and Regards,
Abhijit
AnkurPosted Sep 14, 2010, 3:56 AM
i think following might help:
string filePath = "your path here";
DirectoryInfo[] DInfo = new DirectoryInfo(filePath).GetDirectories();
for (int i = 0; i < DInfo.Count(); i++)
{
try
{
FileInfo[] files = DInfo[i].GetFiles("*.*", SearchOption.AllDirectories);
foreach (FileInfo fInfo in files)
{
//implement your logic here
}
}
catch (Exception ex)
{
//Match Criteria if access permission then ignore
}
}
the trick is to ignore the error caused by access permission.
Thanks and Regards
abhijit walkePosted Sep 14, 2010, 4:52 AM
Here i found best answer using recursion
Thanks and REgards,
Abhijit