Handmade Hero»Forums»Code»what does this mean "\\*" in a string??
76 posts
what does this mean "\\*" in a string??
2 weeks ago Edited by C_Worm on Sept. 10, 2020, 8:53 p.m. 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
2126 posts / 1 project
what does this mean "\\*" in a string??
2 weeks ago Edited by Mārtiņš Možeiko on Sept. 10, 2020, 11:19 p.m.
\\ 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
882 posts
what does this mean "\\*" in a string??
2 weeks ago
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.
76 posts
what does this mean "\\*" in a string??
1 week, 5 days ago
Allright! thanks for clearing that out for me! :)