Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read all files

Status
Not open for further replies.

Dave60608

Programmer
Mar 22, 2021
3
0
0
US
I am trying to read all of the files under a specified starting directory. The code I am using is:
ThisPathItems.AddRange(Directory.GetFiles(lblIPPath.Text, "*.*", SearchOption.AllDirectories));
foreach (string pn in ThisPathItems)
{
strCDFPathName = Path.GetDirectoryName(pn); // directory name without file name
}

The trouble is, when I run this on the root directory, it tries to process the "System Volume Information" directory, and it crashes.
I have looked on Google for an example of how to handle this, but I can find nothing. One part said to use DirectoryInfo.GetFiles instead, but there were no examples, so I came up empty.

Does anyone know how I can get out of this bind?
Thanks much!
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top