DirectoryInfo.GetFiles(Mask) finding too many files!

  • Thread starter Aaron via DotNetMonster.com
  • Start date
A

Aaron via DotNetMonster.com

I am testing for several file types in a directory by creating an array of masks and for each mask in the array, I execute a GetFiles.

My issue is that the VB code:

myDirectoryInfo.GetFiles("*.asp")

is returning not only .asp files, but .aspx files in the directory as well!!!

A test from the Windows command line found that the command "dir *.asp" also returns .aspx files in the directory as well as .asp. This is obviously an issue with the OS so without getting into a Windows Vs. myOS discussion, how can this issue be overcome?

One idea I had is to do a GetFiles("*.*") and then itterate through my mask array and remove files which don't match the masks in the array, but this seemed like an inefficient process.

Your ideas are appreciated!
 
K

Ken Cox [Microsoft MVP]

I suppose you could just check the length of the extension once you have all
of the .asp* files. It sure seems odd.

I'm curious as to Microsoft's rationale for the behaviour you're seeing when
passing three characters of the extension. It appears to be by design and
not a bug... perhaps to maintain compatibility?

"The matching behavior of searchPattern when the extension is exactly three
characters long is different from when the extension is more than three
characters long. A searchPattern of exactly three characters returns files
having an extension of three or more characters. A searchPattern of one,
two, or more than three characters returns only files having extensions of
exactly that length."

http://msdn.microsoft.com/library/d...fsystemiodirectoryinfoclassgetfilestopic2.asp
 

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