Directory.Getfiles issue

  • Thread starter Thread starter OpticTygre
  • Start date Start date
O

OpticTygre

I have a directory of 27 files. The files end in either 1.txt, 2.txt,
3.txt, or 4.txt.

If I say:

For Each filename As String In
Directory.GetFiles("C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\",
"*1.TXT")
Debug.WriteLine(filename)
Next

It prints out the following:

C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\E310920041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\E311020041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\HEI173680920044.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\HEI173680920042.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\HEI173680920043.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\HEI173680720041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\HEI173680920041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\R70136020720041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\R70309010820041.txt
C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\R70332090920041.txt

Obviously, this is not correct. If my search string is "*2.TXT", "*3.TXT",
or "*4.TXT" it prints out alright. Has anyone seen this behavior before in
Directory.GetFiles?

-Jason
 
The odd part is, if I change the code to:

Dim sFiles() As String =
Directory.GetFiles("C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\",
"*.txt")

For Each filename As String In sFiles
If filename.EndsWith("1.txt") Then Debug.WriteLine(filename)
Next

Then it prints out the correct information. Why would a search string of
*1.txt return things that don't end in 1.txt?
 
Optic,
All of the "wrong" files have long file names, which suggests to me that
their short file name might be something ~1, which would match the *1.TXT".

You can use "dir /x" under the Command Prompt to see the 8.3 file names.

Unfortunately I don't know of any workarounds other then checking the names
returned from Directory.GetFiles. Note this is not to suggest there are not
other ways of limiting the search to long names...

Hope this helps
Jay
 

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

Back
Top