Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
1 rating:
 1 out of 5     Rate this Document

Behavior of GetFirstFile Function with Wildcards



Primary Software:
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
When using the GetFirstFile function and the '?' wildcard, I observe unexpected behavior. In particular, I am trying to retrieve all files that are 8 characters long with the following code:

GetFirstFile ("\\????????.???", . . .);

Instead, the GetFirstFile function returns all the files in the specified search directory. Why am I seeing this behavior and is it to be expected?


Solution:
On Win32 operating systems, the LabWindows/CVI GetFirstFile function is implemented using the Windows SDK FindFirstFile function. The FindFirstFile function accepts two kinds of wildcards: the asterisk (*) and the question mark (?). Since NTFS appeared, Win32 treats the '?' wildcard in special ways depending on the location and search pattern.






Wildcard Behavior
*.* Matches everything in the search directory regardless of the number of periods in a name.
? Matches a single character. If the wildcard is at the end of a name or at a period, all consecutive '?' match.
.? Matches a period followed by a single character. This wildcard will also match at the end of a name.
.* Matches a period followed by any number of characters. This wildcard will also match at the end of a name.
*. Matches 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.






In particular, certain character combinations are given special meaning when used as wildcards. These rules apply to both long and short names. In general, the GetFirstFile and GetNextFile functions return matches similar to the dir shell command.

In order to get all files that are 8 characters long, consider using the '*.*' wildcard, and then filtering the results afterwards.


Related Links:
Microsoft SDK: FindFirstFile
Microsoft SDK: FindNextFile

Attachments:





Report Date: 12/27/2004
Last Updated: 01/04/2005
Document ID: 3GQL3BK7

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit