I use this go get the content of directory foo: FindFirstFile(L"foo\\*", &findData). It works great when foo is a regular directory. However when foo is a junction pointing to another directory (created with mklink /j foo C:\gah) FindFirstFile fails.
The docs have this to 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 the debugger I just get an INVALID_HANDLE_VALUE and findData remains untouched.
So, how do I work around this?
Raymond Chen has an answer for you.
Functions like
GetFileAttributesandFindFirstFile, when asked to provide information about a symbolic link, returns information about the link itself and not the link destination. If you use theFindFirstFilefunction, you can tell that you have a symbolic link because the file attributes will have theFILE_ATTRIBUTES_REPARSE_POINTflag set, and thedwReserved0member will contain the special valueIO_REPARSE_TAG_SYMLINK.Okay, great, so now I know I have a symbolic link, but what if I want information about the link target? For example, I want to know the size of the link target, its last-modified time, and its name.
To do this, you open the symbolic link. The I/O manager dereferences the symbolic link and gives you a handle to the link destination. You can then call functions like
GetFileSize,GetFileInformationByHandleEx, orGetFinalPathNameByHandleto obtain information about the symbolic link target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With