I\'ve been searching around trying to find a way to determine if a file is a junction or not, and have not found any satisfactory answers.
First thing I tried was:
If you can write native code in JNA, you can directly call the Win32 API GetFileAttributes()
function and check for the FILE_ATTRIBUTE_REPARSE_POINT
flag (junctions are implemented as reparse points).
Update: To differentiate between different types of reparse points, you have to retreive the ReparseTag
of the actual reparse point. For a junction point, it will be set to IO_REPARSE_TAG_MOUNT_POINT
(0xA0000003).
There are two ways to retreive the ReparseTag
:
Use DeviceIoControl() with the FSCTL_GET_REPARSE_POINT control code to obtain an REPARSE_DATA_BUFFER struct, which as a ReparseTag
field. You can see an example of an IsDirectoryJunction()
implementation using this technique in the following article:
NTFS Hard Links, Directory Junctions, and Windows Shortcuts
Use FindFirstFile() to obtain a WIN32_FIND_DATA struct. If the path has the FILE_ATTRIBUTE_REPARSE_POINT
attribute, the dwReserved0
field will contain the ReparseTag
.