Handmade Hero»Forums»Code
104 posts
what does this mean "\\*" in a string??
Edited by C_Worm on Reason: Initial post
on msdn they have a "print all files in the directory" example and they say that they "prepare" the string for use with FindFirstFile().

I haven't seen this before but what does it mean?


Why do you have to append it to the directory name?

// Prepare string for use with FindFile functions.  First, copy the
   // string to a buffer, then append '\*' to the directory name.

   StringCchCopy(szDir, MAX_PATH, argv[1]);
   StringCchCat(szDir, MAX_PATH, TEXT("\\*"));

Mārtiņš Možeiko
2452 posts / 2 projects
what does this mean "\\*" in a string??
Edited by Mārtiņš Možeiko on
\\ is because you want to put \ in string. You need to escape it when putting in C string. So "\\" becomes \ in memory.
* is called wildcard - it matches any string. If you use a*b then this matches axxxb, ayzzb, ... - basically anything that starts with a and ends with b. If you use *xx* then this matches anything that has xx in the middle of string - aaxxbb, xxxcc, zzzxx, ...

What their code does is create string in form "c:\path\*" - which means any file "*" under specified folder "c:\path".
Simon Anciaux
1274 posts
what does this mean "\\*" in a string??
The double backslash is to escape an single backslash in a string. In this case it's just to have the backslash separator between the directory name and the file name.

The star * is a wildcard character, a character used to signify that 0 or more character should be present in place of the star character.

The FindFirstFile function searches for the filename you specify. If you specify a directory name without \*, it will return the information about the directory. Since you want all the file in the directory, you use the wildcard to say that the file name is the directory name followed by a \ followed by 0 or more character.

You can be more precise: if you want to retrieve only .txt files, you can use "\\*.txt". If you want file starting with "lib" and finishing with "debug" with any extension you could specify "\\lib*debug.*". Note that I didn't verify those but I expect them to work.
104 posts
what does this mean "\\*" in a string??
Allright! thanks for clearing that out for me! :)