What is the "appearance" of the "symbolic link" ?; -)
- The abbreviated .LNK ? (Win95 +, not transparent)
- A connection point ? (Win2K +, only local file systems / directories)
- True NTFS symlink ? (Vista / 2008 / Win7 +)
Oh, and read the symlink in the Wikipedia article above for the mklink
;-) Back-ticks (or system) may be a good friend, but Note:
The default security settings in Windows Vista / Windows 7 prevent non-administrators and non-administrators from creating symbolic links. This behavior can be changed [using the security policy setting] ....
Happy coding.
The WinAPI CreateSymbolicLink function can be used directly; I am not sure if it is โsufferingโ from the same restriction as the mklink
above. However, this flow indicates that it is still operational.
FWIW, this "works" in Strawberry Perl 5.12. YMMV, I just typed this and never used it otherwise :-)
use Win32::API; $fn = Win32::API->new( # Note "A" function, IDK how to use Unicdoe "kernel32", "BOOLEAN CreateSymbolicLinkA(LPTSTR lpSymlinkFileName, LPTSTR lpTargetFileName, DWORD flags)" ); unlink("src.txt"); unlink("lnk.txt"); open(FH,">src.txt") or die $!; close(FH); print "src.txt exists? " , (-f "src.txt"), "\n"; print "lnk.txt exists? " , (-f "lnk.txt"), "\n"; $hr = $fn->Call("lnk.txt", "src.txt", 0); print "Result: ", $hr, "\n"; print "lnk.txt exists? ", (-f "lnk.txt"), "\n"; open(FH,">>src.txt") or die $!; print FH "hello world!\n"; close(FH); open(FH,"<lnk.txt") or die $!; print "linked data: ", scalar(<FH>), "\n"; close(FH);
My results (run as "Administrator" - may not work for "other users" - I donโt know why, but my cmd.exe always opens with elevated privileges):
src.txt exists? 1
lnk.txt exists?
Result:
lnk.txt exists? 1
linked data: hello world!
Directory List:
10/22/2011 02:53 PM <DIR>.
10/22/2011 02:53 PM <DIR> ..
10/22/2011 02:54 PM 636 foo.pl
10/22/2011 02:53 PM <SYMLINK> lnk.txt [src.txt]
10/22/2011 02:53 PM 14 src.txt
I have no idea what the [subtle] differences can be, if any, between NTFS symbolic links and "UNIX" symbolic links. In addition, pre-Vista / 2008 will not work above - previous versions of NTFS do not support symbolic links (and previous versions of windows do not have the CreateSymbolicLink
function).