sriram83.life has asked for the wisdom of the Perl Monks concerning the following question:
I want to write a script that extracts files in directories and their subdirectories recursively.I have used File::Find module to use wanted() subroutine to extract files recursively.While it recursively extracts,some duplicate files are appearing and asking for prompt to replace or rename. Here is the example prompt.
replace META-INF/MANIFEST.MF? [y]es, [n]o, [A]ll, [N]one, [r]ename:
Every time it appears,script has to send "A" reply to the prompt and it has to continue as i need to extract hundreds of files and get the required file.Can any one give me suggestions on how to write this using perl Expect?
Here is my code which uses File::Find module to find files recursively and perform some actions.
find( { wanted => \&wanted, }, @dirs); sub wanted { my $depth = $File::Find::dir =~ tr[/][]; return if $depth < $min_depth; if ( $File::Find::name =~ m/.zip$|file.*?$/ ) { print "I am extracting zip file : $File::Find::name\n"; &execute_command("unzip $File::Find::name"); #At this point it asks for prompt,i need to make it accept reply +automatically. #execute_command is a subroutine written in another module which +uses fork and exec to execute a shell command. elsif ( $File::Find::name =~ m/.gz$/ ) { &execute_command("gunzip $File::Find::name"); } }
Your help is much appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help on perl Expect Module
by atcroft (Abbot) on Apr 23, 2014 at 05:11 UTC | |
|
Re: Need help on perl Expect Module
by kcott (Archbishop) on Apr 23, 2014 at 05:36 UTC | |
by sriram83.life (Acolyte) on Apr 23, 2014 at 06:08 UTC | |
|
Re: Need help on perl Expect Module
by salva (Canon) on Apr 23, 2014 at 08:10 UTC | |
by mr_mischief (Monsignor) on Apr 24, 2014 at 21:00 UTC |