[英]how to make symbolic link between file in folders using perl?
here is the scenario. 这是场景。
I have dir1-->file1
|-->file2
|-->subdir1--->file3
| |---> file4
|
|-->file1
|-->subdir2-->file6
also dir2 different file tree... 也dir2不同的文件树...
I need to symlink above file in /path/dir1 and /path/dir2 to anthor path call /newpath/dir1 and /newpath/dir2.. 我需要将/ path / dir1和/ path / dir2中的文件上方符号链接到路径调用/ newpath / dir1和/ newpath / dir2。
is it possible? 可能吗?
So far i tried below 到目前为止,我尝试了以下
#!/usr/bin/perl
use strict;
use File::Find qw(find);
my $path = "path";
find(\&Search, $path);
sub Search{
my $filename = $File::Find::name;
if(-f $filename){
symlink("$filename", "path2");
}
}
symlink($filename, "path2/" . $_);
Should do the trick. 应该做到的。 Always assuming "path2"
is the directory where you want the links to be place. 始终假设"path2"
是您要放置链接的目录。
Finally i went with below method. 最后我用下面的方法。
my $dir = "/path/";
my $smlinkdir = "/smlink/path/";
chdir($smlinkdir) or die "Cant chdir to $smlinkdir $!";
if(-d $smlinkdir) {
system(cp, '--recursive', '--preserve=all', '--no-dereference', '--symbolic-link', "$dir", "$smlinkdir");
} else {
exit 1
}
this worked as well and i went with this since this gives the output i expected. 这也很好,我继续这样做,因为这给出了我期望的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.