FindFirstFile and Junctions

I use this, get the contents of the foo directory: FindFirstFile(L"foo\\*", &findData) . It works fine when foo is a regular directory. However, when foo is a connection pointing to another directory (created using mklink /j foo C:\gah ), FindFirstFile fails.

The documents should say: "If the path points to a symbolic link, the WIN32_FIND_DATA buffer contains information about the symbolic link, not the target." But when I run it with a debugger, I just get INVALID_HANDLE_VALUE and findData remains untouched.

So how do I get around this?

+6
source share
1 answer

Raymond Chen has one for you.

Functions such as GetFileAttributes and FindFirstFile , when asked to provide information about a symbolic link, returns information about the link itself, not the link. If you use FindFirstFile , you can say that you have a symbolic link because the file attributes will have FILE_ATTRIBUTES_REPARSE_POINT the flag is set and the dwReserved0 element will contain the special value IO_REPARSE_TAG_SYMLINK .

Ok, fine, now I know that I have a symbolic link, but what if I want information about the target link? For example, I want to know the size of the link target, its last modified time and its name.

To do this, you open a symbolic link. The I / O Manager sections are a symbolic link and gives you a link to the link. You can then call functions like GetFileSize , GetFileInformationByHandleEx or GetFinalPathNameByHandle to get information about the purpose of the symbolic link.

+9
source

Source: https://habr.com/ru/post/893383/


All Articles