我在我的脚本中有这个目录路径c:/ server/THE/BPS_DATA/THE_1,我需要检索文件夹名称,这是两个以上的目录.
在我的例子中,我需要检索值THE
我尝试使用fileparse
my($datapath) = "c:/server/THE/BPS_DATA/THE_1";
print " datapath is: $datapath\n";
my($filename, $bpsPath, $suffix) = fileparse($datapath);
Run Code Online (Sandbox Code Playgroud)
这里返回c:/ server/THE/BPS_DATA/
有什么建议?
use Path::Class qw( dir );
say dir('c:/server/THE/BPS_DATA/THE_1')->parent->parent;
Run Code Online (Sandbox Code Playgroud)
哦等等,我看到你只想要"THE"?
use Path::Class qw( dir );
say dir('c:/server/THE/BPS_DATA/THE_1')->parent->parent->basename;
Run Code Online (Sandbox Code Playgroud)
要么
use Path::Class qw( dir );
say( (dir('c:/server/THE/BPS_DATA/THE_1')->dir_list)[-3] );
Run Code Online (Sandbox Code Playgroud)