perl - How to retrieve the folder name of a given dir? -
i have dir path c:/server/the/bps_data/the_1 in script , need retrieve folder name 2 dirs above this.
in example need retrieve value the
i tried fileparse of
my($datapath) = "c:/server/the/bps_data/the_1"; print " datapath is: $datapath\n"; my($filename, $bpspath, $suffix) = fileparse($datapath);
here returns c:/server/the/bps_data/
any advice?
use path::class qw( dir ); dir('c:/server/the/bps_data/the_1')->parent->parent;
oh wait, see want "the"?
use path::class qw( dir ); dir('c:/server/the/bps_data/the_1')->parent->parent->basename;
or
use path::class qw( dir ); say( (dir('c:/server/the/bps_data/the_1')->dir_list)[-3] );
Comments
Post a Comment