I'm using Oracle Java 7 on Windows 64 bit.
When I create a symlink using Files.createSymbolicLink, I notice this behavior:
- If the target is a directory, a "directory symlink" is created.
- If the target is a file, a "file symlink" is created.
- If the target does not exist, a "file symlink" is created.
The type of the symlink is fixed and never changes, regardless of any changes to its target.
Using Windows' native mklink
command, it is possible to force the link type to be a "directory symlink". Is it possible to achieve this using the native Java API or some library?
One trivial and ugly way is:
- If the target is a directory, just create the link
- If the target doesn't exist, create a new empty target directory, create the link, and delete the directory.
- If the target is a file ... handle it (move it, apply #2, move it back).
Fugly.