- 论坛徽章:
- 0
|
原帖由 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:
- #!/usr/bin/perl -s
- sub ScanDirectory{
- my ($workdir) = shift;
- opendir(DIR, $workdir)or die "unable to open $!\n";
- my @names = readdir(DIR);
- closedir(DIR);
- foreach my $name(@names){
- next if $name eq "." || $name eq "..";
- my $fullname = $workdir. '/'. $name;
- # don't make -l recursively!
- if (-d $fullname && ! -l $fullname){
- &ScanDirectory($fullname);
- } else {
- # display link file:
- if (-l $fullname) {
- print "-l: $fullname\n";
- }
- }
- }
- }
- &ScanDirectory($ARGV[0] ? $ARGV[0} : '.');
复制代码
-- ulmer |
|