Java – determines whether a file is a connection (in Windows)?

I've been looking for a way to determine whether a file is a connection point, and I haven't found any satisfactory answer

The first thing I tried was:

Files.isSymbolicLink(aPath)

It only detects symbolic links, not files called connections in windows

I also tried the solution proposed here (using the JNA Library): stack overflow question (3249117), but I never recovered any files I thought were intersections correctly

I found that the only way to determine which files are connection points is to run the following command at the windows command prompt:

DIR /S /A:L

On my computer, it returns 66 folders, files Issymboliclink (apath) returns only 2 So I think I can find a way to take advantage of this, but I don't think it will be efficient to traverse a file tree

Is there any way to use standard Java libraries or replace JNA?

Solution

If you can write local code in JNA, you can directly call the Win32 API getfileattributes() function and check the file_ ATTRIBUTE_ REPARSE_ Point flag (whether the connection is implemented as a reanalysis point)

Update: in order to distinguish different types of reanalysis points, you must retrieve the reparsetag of the actual reanalysis point For connection points, it will be set to io_ REPARSE_ TAG_ MOUNT_ POINT(0xA0000003).

There are two ways to retrieve reparsetag:

>Using deviceiocontrol() and FSCTL_ GET_ REPARSE_ The point control code obtains a reparse_ DATA_ Buffer structure 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 get a Win32_ FIND_ Data structure If the path has file_ ATTRIBUTE_ REPARSE_ Point attribute, dwreserved0 field will contain reparsetag

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>