Question on Directory.GetFiles()

  • Thread starter Thread starter Michael Jackson
  • Start date Start date
M

Michael Jackson

In my .NET 2.0 VS 2005 VB application, I'm using Directory.GetFiles(path) to
get all the files in the directory. However, I'm getting an error regarding
"Illegal character in Path", even though I can copy, etc the file using the
Windows XP explorer.

I can trap the error, but then this traps the entire GetFiles() function,
not just the one bad file.

Is there a way to just trap for the one bad file and continue on?

Michael
 
Michael Jackson said:
In my .NET 2.0 VS 2005 VB application, I'm using Directory.GetFiles(path) to
get all the files in the directory. However, I'm getting an error regarding
"Illegal character in Path", even though I can copy, etc the file using the
Windows XP explorer.

I can trap the error, but then this traps the entire GetFiles() function,
not just the one bad file.

Is there a way to just trap for the one bad file and continue on?

Michael

It is very likely the path you are sending it is wrong and has the bad
character.
 
Yes, there is a bad character in one of the paths. Odd thing though, .NET
fails on it, but I can move, copy, etc through windows. I'm getting a list
of files from a copy of another hard drive. The file was created and saved
through Microsoft Word. How can Microsoft Word create a file name that .NET
cannot access through GetFiles().

When the GetFiles function encounters a file name with a bad character, the
function throws an exception, and the String Array being populated by the
GetFiles function is Nothing.

I just can't believe this is how Microsoft wrote this function. Why can it
not AT LEAST give me the files that do not have illegal characters in the
file name.

Thanks,

Michael
 
I'm sorry. I re-read the reply to my question and I see what you are saying
about passing in a path with an illegal character in it.

No, that is not the case, because I'm also getting the directories of that
directory via GetDirectories, and I do that BEFORE the GetFiles function.
When stepping thru the code in debug, I can see that I'm getting an array of
Directores.

Thanks
Michael
 
Back
Top