CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Creating relative symbolic links

 



tbone587
User

May 19, 2011, 2:40 PM

Post #1 of 7 (1907 views)
Creating relative symbolic links Can't Post

Is there any way to create relative symbolic links with the "symlink" function? I can only get it to work when i use absolute paths. I want the link to look like file --> ../file. Any help would be greatly appreciated.


miller
User

May 19, 2011, 3:37 PM

Post #2 of 7 (1905 views)
Re: [tbone587] Creating relative symbolic links [In reply to] Can't Post

If it doesn't work, it could simply be a limitation of your system. Creating relative symlinks works fine for me on linux using perl.

- Miller


tbone587
User

May 19, 2011, 3:47 PM

Post #3 of 7 (1902 views)
Re: [miller] Creating relative symbolic links [In reply to] Can't Post

Miller,
Its not a limitation of my system, I just cant seem to figure out the correct syntax via perl. I am currently doing it using the method below, which works perfectly, but I want to clean it up a bit and make it more efficient.


Code
 #################### Link Files ########################################################### 

my $Link_UserFiles_Sub = "ln -s ../Polycom-user-$MatchMac.cfg";
my $Link_MacFiles_Sub = "ln -s ../$MatchMac.cfg";

chdir($CustomerPath) or die "Cannot chdir to $CustomerPath $!";
system $Link_UserFiles_Sub; #Links the files to the sub directories
system $Link_MacFiles_Sub; #Links the mac files to the sub directories

chdir($TftpbootPath) or die "Cannot chdir to $TftpbootPath $!"; #Return back to /tftpboot

############################################################################################


Basically I have a file located /directory/file.cfg, and i want to create a relative symlink in /directory/test/file.cfg. After complete, when I do an "ls -l" from /directory/test, I should see file.cfg --> ../file.cfg.


miller
User

May 19, 2011, 4:39 PM

Post #4 of 7 (1900 views)
Re: [tbone587] Creating relative symbolic links [In reply to] Can't Post

Just read the documentation for symlink


Code
chdir("/directory/test"); 
symlink("../file.cfg", "file.cfg");



tbone587
User

May 19, 2011, 6:59 PM

Post #5 of 7 (1894 views)
Re: [miller] Creating relative symbolic links [In reply to] Can't Post

Thanks miller I will try that out. I was trying to get it done without that chdir, but I guess its still needed.


miller
User

May 19, 2011, 7:01 PM

Post #6 of 7 (1893 views)
Re: [tbone587] Creating relative symbolic links [In reply to] Can't Post

Well... give the following a try. Should work too:

Code
symlink("../file.cfg", "/directory/test/file.cfg");



tbone587
User

May 19, 2011, 7:24 PM

Post #7 of 7 (1891 views)
Re: [miller] Creating relative symbolic links [In reply to] Can't Post

That worked beautifully, thank you very much! That cleaned up my script quite a bit.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives