in reply to unrar from multiple directories

Hi

But i don't know how to make it to search in every folder.
One of the ways of doing that, is using either a recursive subroutine, or use File::Find module.
Using a recursive subroutine:
For Example: To list out all the files in different folders in a directory like so:

use warnings; use strict; scan_dir( $ARGV[0] ); ## call subroutine sub scan_dir { my ($dir) = @_; if ( -d $dir ) { ## check if directory opendir my $dh, $dir or die "can't open directory: $!"; while ( readdir $dh ) { next if $_ eq '.' or $_ eq '..'; print $_, $/; scan_dir("$dir/$_"); ## recursive call } } }
This can even get simplier using a File::Find module like so:
use warnings; use strict; use File::Find qw(find); find(\&scan_dir,$ARGV[0]); sub scan_dir{ return if $_ eq '.' or $_ eq '..'; print $_,$/; }
NOTE:Please, that the codes above is to show how you can transverse a dircetory. To get your rar files, and "unrar", is left for you to figure out. Am sure you will get around it! :)
Check perldoc File::Find for more info.
Cheers.

Replies are listed 'Best First'.
Re^2: unrar from multiple directories
by cesapun (Acolyte) on Aug 09, 2012 at 19:38 UTC

    Thank you very much.

      I will stay all night to find a way to handle with .rar files.

        Something like -

        sub scan_dir{ unless( $_ =~ /\.rar$/ ) { return; } print $_,$/; }

        should do it.

        J.C.