Perl Get Parent Folder Name -
what solution name of parent directory using file::find. know how filename or directory path don't know how last containing directory.
for example, if directory /dir_1/dir_2/dir_3/.../dir_n/*.txt
need 'dir_n
' name.
use strict; use warnings; use file::find; $dir = "some_path"; find(\&file_handle, $dir); sub file_handle { /\.txt$/ or return; $fd = $file::find::dir; $fn = $file::find::name; # ... }
given directory path, apply file::basename (another core module) path obtain last portion of directory.
use strict; use warnings; use file::find; use file::basename; $dir = "some_path"; find(\&file_handle, $dir); sub file_handle { /\.txt$/ or return; $fd = $file::find::dir; $fn = $file::find::name; $dir = basename($fd); # .... }
Comments
Post a Comment