免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4086 | 回复: 0
打印 上一主题 下一主题

求教,递归遍历查找符号链接文件问题。 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2007-02-27 17:25 |显示全部楼层
原帖由 aman13 于 2007-2-27 14:01 发表
写了一个perl script, 想找出所有的符号链接文件。比如
dir001----file1
          |---file2
          |---link1
          |---link2
          |---dir002----file3
                        |----link ...


Hi,

allways attention to absolute and relative path in opendir(...).
readdir(...) returns only relative file or dir name.
if you want to check -l under reursivie dir, should check -l too, not only -d:
i.e: sample code:

  1. #!/usr/bin/perl -s

  2. sub ScanDirectory{
  3.     my ($workdir) = shift;
  4.     opendir(DIR, $workdir)or die "unable to open $!\n";
  5.     my @names = readdir(DIR);
  6.     closedir(DIR);

  7.     foreach my $name(@names){
  8.         next if $name eq "." || $name eq "..";
  9.         my $fullname = $workdir. '/'. $name;
  10.         # don't make -l recursively!
  11.         if (-d $fullname && ! -l $fullname){
  12.             &ScanDirectory($fullname);
  13.         } else {
  14.             # display link file:
  15.             if (-l $fullname) {
  16.                 print "-l: $fullname\n";
  17.             }
  18.         }
  19.     }
  20. }

  21. &ScanDirectory($ARGV[0] ? $ARGV[0} : '.');

复制代码



-- ulmer
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP