GetFiles

  • Thread starter De Angelis Piergiulio - ITS snc
  • Start date
D

De Angelis Piergiulio - ITS snc

Hi,
I'm developing with VB.NET an application for pocket pc.

Somebody can tell me why this simple code generate error on
Directory.GetFiles("\Program Files", "*.wav") ?

For Each FileName In Directory.GetFiles("\Program Files", "*.wav")
MsgBox(FileName)
Next

Directory.GetFiles is supported on Compact Framework !

Thanks
Piergi
 
C

Chris Tacke, eMVP

What error? On which line? I'm no VB expert, but your ForEach doesn't look
right to me. There's probably supposed to be an instantiation somewhere.
 
P

Peter Foot [MVP]

I'm just guessing (since you haven't told us what the error is) but it could
be this minor change to your code:-

For Each FileName As String In Directory.GetFiles("\Program Files", "*.wav")
MsgBox(FileName)
Next

Peter
 
D

Daniel Moth

If it is at compile time then obviously you haven't declared FileInfo As
String.

If it is at runtime then tell us what the exception is. FYI that code works
fine over here so it is not a CF issue.

Cheers
Daniel
 
D

De Angelis Piergiulio - ITS snc

Hi,
this is the error:

Eccezione non gestita di tipo "System.IO.IOException" in mscorlib.dll

Informazioni aggiuntive: IOException
 
D

Daniel Moth

Hmmm... According to documentation (and my experience is consistent with it)
you cannot get an IOException; instead you get a DirectoryNotFoundException
in most cases.

Having said that, a web search produces cases where people have observed an
IOException from Directory.GetFiles. In those cases the culprit was either a
file named the same as the directory, or an empty directory, or a network
drive that was not ready or a timing issue where the directory was just
created in code. In all of those cases I still observe a
DirectoryNotFoundException.

If I were in your shoes I'd try the following in order to narrow down where
the problem is:
1. Not sure where you are calling it from. Try from a button click with
nothing else in the method. Decouple the foreach from the explicit method
call.
2. Append a \ to the call i.e. Directory.GetFiles("\Program Files\",
"*.wav")
3. Try the call without a filter i.e. Directory.GetFiles("\Program Files\")
4. Try it on a different directory that you have created via file explorer
5. Try it on an English setup (sounds like you are on an Italian setup)

Let me know if any of the above makes a difference or if you have found the
cause of the exception.

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top