Let me take some notes about "*.*"
vs "*"
. These filers are not equal.
2 different files can exist in our folder: somefile
and somefile.
.
If we used the low level api ZwQueryDirectoryFile
with "*.*"
as a search expression (this is the 10th parameter - FileName [in, optional]
) - we would get somefile.
only. But if we used "*"
we'd get both files - somefile
and somefile.
If we try FindFirstFile("C:\\semester2\\*.*", &data);
we can note than both files somefile
and somefile.
are returned. So here "*.*"
vs "*"
have the same effect - no difference in usage.
Why does this happen? Because inside FindFirstFileEx
in kernelbase
(kernel32
) do special check for "*.*"
mask and if it true - replace to ""
(An empty name which have the same effect as "*"
).
I think this is done to fix a very common error when users pass "*.*"
instead of the correct "*"
and for backward compatability with legacy code.
.
and ..
aren't actually part of the directory as it is stored on
disk, but are added by the Win32 API.
This is not true.
- for
FAT
-style file system this is really stored on FAT directory as 2 first entry.
- in
NTFS
there are no such entries, but NTFS.sys
artificially add this 2 entries if they in mask.
So this is done not at Win32 API level, but in kernel - on driver level.
In conclusion, "*.*"
will work correct with Win32 API how minimum now - but the correct and clean way is to use "*"
here.
"*.*"
will be mistake with ZwQueryDirectoryFile
api.
W
suffix toWIN32_FIND_DATA
,FindFirstFile
, &FindNextFile
,L
prefix to path literal, replacestd::cout
withstd::wcout
) or usingTCHAR
s consistently (add#include <tchar.h>
, make the string literal_T("C:\\semester2")
, and conditionally aliasstd::tcout
tostd::cout
/std::wcout
as appropriate). – Ramah