locked
Problem with using wildcards in My.Computer.FileSystem.GetFiles() RRS feed

  • Question

  • Hi,

     

    I've noticed a problem using wildcards in My.Computer.FileSystem.GetFiles(), suppose I use the wildcard expression "*.doc", not only will it match all "*.doc" files, but it also matches all "*.docx" files. Is this by design? Is there any workarounds I can use if I only want it to match just "*.doc" files? I guess I could pull out all file names test it using "Like", or regular expressions, but doesn't seem to be like a very efficient solution. Note that Directory.GetFiles() has the same behaviour, the one in My namespace is probably just a wrapper around it anyway.

     

    Wednesday, July 11, 2007 8:42 AM

Answers

  • RyanTsai,

     

    1. There is 3-Symbol Extension Wildcards desclaimed in MSDN:

     

    NOTE: If you pass "*.htm" wildcard to GetFiles you will also get files with ".html" extension. 

    It is often acceptable for .html and .html, but it is not always obvious why .1234 is returned if *.123 is requested.

    This behavior is due to short file name in 8.3 format.

     

    http://msdn2.microsoft.com/en-us/library/6zwyt2y8(VS.80).aspx

    2. If you consider the result is by design, I recommend you to test with "*.docx" wildcard and see if there are any "doc" files shown.

     

    Hope that can help you with the problem.

    Monday, July 16, 2007 7:01 AM