FindFirstFile and "." / ".." record attributes

filesystems, winapi, windows

Solution

From MSDN:

Use a period as a directory component in a path to represent the current directory...

Use two consecutive periods (..) as a directory component in a path to represent the parent of the current directory

It means `.` is current directory and you may rely that they attributes are the same. But anyway I don't understand why can't you just ignore the dot and dotdot files.

Problem

What object is the meta-data of the dot/double-dot file records as returned by FindFirstFile on a directory referring to? In practice they seem to behave as a curious mixture of soft and hard links. On my system the file attributes (e.g. read-only/hidden/archive flags) do reflect the state of the target they point towards, however the creation/write/access access fields always seem to equal the creation time of the directory being searched. I ask because a build tool I was working on decided to cache search results by first translating the file names to absolute ones and filing away the meta-data, leading broken builds when the creation-times of later directories mismatched. May I rely on the ftCreationTime of "." being equal to the creation time of the folder itself? This would be useful in avoiding unnecessary queries. For the record here is a quick-and-dirty repro: ``` #include <stdio.h> #include <windows.h> static void print(const WIN32_FIND_DATAA *data) { printf("name=%s attrib=%08lX creation=%08lX%08lX\n", data->cFileName, data->dwFileAttributes, data->ftCreationTime.dwHighDateTime, data->ftCreationTime.dwLowDateTime); } int main(void) { WIN32_FIND_DATAA data = { 0 }; HANDLE handle = FindFirstFileA("C:\\Windows\\System\\*", &data); print(&data); FindNextFileA(handle, &data); print(&data); FindFirstFileA("C:\\Windows", &data); print(&data); FindFirstFileA("C:\\Windows\\System", &data); print(&data); return 0; } ```

Original source