LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected behaviour calling GetFirstFile with wildcards

Running an 'old' application with CVI 7.1 and Windows XP I noted an unexpected behaviour
using the GetFirstFile library call with "?" wildcard.

Suppose we want to retrieve, inside a directory, all the files which name is 8 characters long,
plus 3 characters for extension.

The code will look like:

GetFirstFile ("\\????????.???", 1, 0, 0, 0, 0, 0, sFoundFile);

Suppose contains the following files:

try.txt
matching.txt
12345678.txt
nomatch.txt

GetFirsFile and subsequent calls to GetNextFile will retrieve all the files inside ,
while the expected behaviour is having the functions to retrieve just "matching.txt" and "12345678.txt"
(8.3 characters long).

The problem didn't occur with CVI 5 or 6.
0 Kudos
Message 1 of 4
(3,437 Views)
In CVI for Win32 platforms, the behavior of GetFirstFile/GetNextFile functions was changed to conform to Win32 wildcard rules. On Win32, the '?' wildcard represents a single character (not zero or one character). To get all the files in a directory, use *.* as the search pattern.

- Mohan
0 Kudos
Message 2 of 4
(3,416 Views)
Hello Makd,

This issue appears due to how Microsoft implements wildcards since NTFS appeared.

In particular: "

Certain character combinations appear to be given special meaning in
wildcard specifications:

*.* is mapped to * - match anything, regardless of how many periods it
contains (even 0).


? matches any single character, or if at the end of the name or at a period,
casues all subsequent, consequetive ? to also match. (So foo??.bar will
match foo.bar, foo1.bar and foo2.bar).


.? will match a period followed by any character and will also match at end
of name (so foo.? will match foo and foo.1).


.* will match a period followed by any characteres, and will also match at
end of name (so foo.* will match foo and foo.1 and foo.bar).


*. will match all characters up to and including the last period in the
name. Names that contain no periods are treated as if they end with a
period (soo 'foo' and 'foo.' are the same file).


If none of the above patterns holds true, then * matches any sequence of
characters.


Any character other than . ? * matches only intself (possibly case
insensitively).


These rules are applied to both the long and short names - any file that
matches either name will be returned by FindFirstFileExW (and all the other
FindFile APIs).


"

I would suggest using the generic wildcards (*.*) in the GetFirstFile function and then do filtering afterwards.


Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 3 of 4
(3,409 Views)
Sorry, Makd. I misread your post. Wendy is correct. Win32 treats the '?' wildcard in special ways depending on the location and search pattern. Basically, GetFirstFile/GetNextFile should return matches similar to the dir shell command.

- Mohan
0 Kudos
Message 4 of 4
(3,403 Views)