I have a directory with multiple sub directories that contain .doc files. Example:
C:\Users\tmedina\Documents\testenviroment\Released\500\test0.doc
C:\Users\tmedina\Documents\testenviroment\Released\501\test1.doc
C:\Users\tmedina\Documents\testenviroment\Released\502\test2.doc
...
C:\Users\tmedina\Documents\testenviroment\Released\520\test20.doc
In my code below, I am trying to display in a list box all of the files that end with extension ‘.doc’ that are in sub directories of C:\Users\tmedina\Documents\testenviroment\Released
So for example, I have
Dim root As String = "C:\Users\tmedina\Documents\testenviroment"
For Each fileFound As String In Directory.GetFiles(Path.Combine(root, "Released\*\*.doc"))
ListBox1.Items.Add(fileFound)
Next
But it keeps throwing out Illegal characters in path error.
Any suggestions on what I’m doing wrong?
The filesystem doesn’t understand the double
*inreleased\*\*.docDirectory.GetFiles oveload that takes only one argument doesn’t like the partial path specification (….*.doc)
Try with this
The Visual Basic language doesn’t need to escape the
\character.The Directory.GetFiles has an overload that takes your base path, a wildcard search string, and an option to search all of the subfolders of the base path.