perl – 获取给定路径下的目录名称

前端之家收集整理的这篇文章主要介绍了perl – 获取给定路径下的目录名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图获取给定路径下所有第一级目录的名称.

我试图使用File::Find但有问题.

有人可以帮助我吗?

解决方法

使用-d文件检查运算符:

#!/usr/bin/perl

use strict;
use warnings;
use autodie;

my $path = $ARGV[0];
die "Please specify which directory to search" 
    unless -d $path;

opendir( my $DIR,$path );
while ( my $entry = readdir $DIR ) {
    next unless -d $path . '/' . $entry;
    next if $entry eq '.' or $entry eq '..';
    print "Found directory $entry\n";
}
closedir $DIR;

猜你在找的Perl相关文章