perl 遍历目录 [英] perl iterate through directories

查看:44
本文介绍了perl 遍历目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取指定路径中所有目录的名称

I'm trying to get the name of all directories in the specified path

我尝试了以下操作,但这使我不仅在我指定的路径上向下移动了每一层

I tried the following but that gives me every level down not just at the path i specified

find(\&dir_names, "C:\\mydata\\");
sub dir_names {
    print "$File::Find::dir\n" if(-f $File::Find::dir,'/');
}

推荐答案

my @dirs = grep { -d } glob 'C:\mydata\*';

这篇关于perl 遍历目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆