http://www.perlmonks.org?node_id=601693

Samy_rio has asked for the wisdom of the Perl Monks concerning the following question:

G'day monks, I have a problem in File::DirWalk. My tried code as:

use strict; use warnings; use File::DirWalk; my $folder = 'E:\test\foldersize\1-folder|E:\test\foldersize\2-folder| +E:\test\foldersize\5-folder'; my $depth = 3; my @directory = grep!/^\s*$/, split/\|/, $folder; my @folder; for my $directory (@directory){ my $dw = new File::DirWalk; $dw->onDirLeave(sub { my ($dir) = @_; return File::DirWalk::FAILED if ($dir eq $directory); push (@folder, $dir); return File::DirWalk::SUCCESS; }); $dw->setDepth($depth); $dw->walk($directory); } $,="\n"; print @folder;

Output as:

E:\test\foldersize\1-folder\Allworth\Copy of VTT E:\test\foldersize\1-folder\Allworth\VTT E:\test\foldersize\1-folder\Allworth E:\test\foldersize\1-folder\Brepols\ARA E:\test\foldersize\1-folder\Brepols E:\test\foldersize\1-folder\Else_UK\KAST2 E:\test\foldersize\1-folder\Else_UK E:\test\foldersize\2-folder\Allworth\VTT E:\test\foldersize\2-folder\Allworth E:\test\foldersize\2-folder\Brepols\ARA E:\test\foldersize\2-folder\Brepols E:\test\foldersize\2-folder\Else_UK\KAST2 E:\test\foldersize\2-folder\Else_UK E:\test\foldersize\5-folder\Allworth\VTT E:\test\foldersize\5-folder\Allworth E:\test\foldersize\5-folder\Brepols\ARA E:\test\foldersize\5-folder\Brepols E:\test\foldersize\5-folder\Else_UK\KAST2 E:\test\foldersize\5-folder\Else_UK

But i need only last folder path. That is, 3rd depth folder path only.

E:\test\foldersize\1-folder\Allworth\Copy of VTT E:\test\foldersize\1-folder\Allworth\VTT E:\test\foldersize\1-folder\Brepols\ARA E:\test\foldersize\1-folder\Else_UK\KAST2 E:\test\foldersize\2-folder\Allworth\VTT E:\test\foldersize\2-folder\Brepols\ARA E:\test\foldersize\2-folder\Else_UK\KAST2 E:\test\foldersize\5-folder\Allworth\VTT E:\test\foldersize\5-folder\Brepols\ARA E:\test\foldersize\5-folder\Else_UK\KAST2

How to acheive this? Any special function available in File::DirWalk itself? Thanks in advance.

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';