Question : Directory.GetFiles() returns error "illegal charactes in path". Need workaround.

In my VB.NET 2.0 application, I'm using Directory.GetFiles() to get the files from a  drive of other peoples PC's. I am recursivly navitaging subfolders, and for each folder, calling the GetFiles() function. On one or more folders, I am geting an exception from GetFiles, "Illegal Charcters inPath". When this exception is thrown, the string array of filenames that GetFiles returns is nothing. So, GetFiles is apparently all or nothing.

Is there anyway to at least get the files that would not throw an exception, in the case where a folder has more than one file but only one file contains illegal characters in the path.

Any alternative is viable, in that this is a forensics applicaiton, and I really need, at least, all the file names, and a FileInfo object of any file that would not throw an exception.

Answer : Directory.GetFiles() returns error "illegal charactes in path". Need workaround.

A thought just struck me as I pressed submit on that.

What happens if you run a Dir command on a directory containing invalid file names from the DOS prompt, rather than from within Windows?  Does that include the illegal names/characters, or fail completely, or what?  If it includes the illegals it might be possible to redirect that to a text file and then read that as input to a VB.NET program structured to avoid them.

Just a thought ....

Roger
Random Solutions  
 
programming4us programming4us