Home: Perl Programming Help: Beginner:
change directory in windows and extract the files from a .zip file inside the folder



sreevno
New User

Sep 11, 2012, 9:55 PM


Views: 2172
change directory in windows and extract the files from a .zip file inside the folder

I am trying a script where I am in directory C:/perl64/bin/extract. My perl script is in this directory and .caz(form of zip) files are also there in this directory. My script creates another directory in the above directory using the names of .caz files. and copied them into respective folders. I am trying to extract this .caz files in the newly created directory i.e C:/perl64/bin/extract/$newdir(name as .caz file). When I am excuting the scirpt the files are extracting at C:/perl64/bin/extract , but I want to change to new directory and extract eh fiel inside that. Please help me. code I am using is below. I tried servral options to "cd" in windows but not able to execute the file inside the new directory.


Code
 
open(DAT, $data_file);
my @raw_data = <DAT>;
foreach my $fileLine1 (@raw_data) {
chomp($fileLine1);
my @dir = split('\.caz',$fileLine1);
foreach my $newdir (@dir){
chomp($newdir);
mkdir $newdir;


my $newdir1 = "$dir\\$newdir";

opendir(DIR, $dir) or die "can't opendir $dir: $! \n";
@files=readdir(DIR);
closedir DIR;

my $oldfile="$dir\\$newdir.caz";

copy($oldfile, $newdir1) or die "File cannot be copied";
#my $final_dest= "C:\\Perl64\\bin\\extract\\$newdir";
#my $cmd1 = system("cmd /K cd /d $newdir1");
#my $cmd1= "cd C:\\Perl64\\bin\\extract\\$newdir";
my $cmd1= 'cd C:\Perl64\bin\extract\$newdir';
open (CMD, "|$cmd1") or die "fail1";
#chdir("C:\\Perl64\\bin\\extract\\$newdir\\");
#print $cmd1;
my $cmd = "cazipxp -u $newdir\.caz";
my %newfiles = open (CMD, "|$cmd") or die "fail";


}}



FishMonger
Veteran / Moderator

Sep 12, 2012, 6:19 AM


Views: 2168
Re: [sreevno] change directory in windows and extract the files from a .zip file inside the folder

See File::chdir - a more sensible way to change directories
http://search.cpan.org/~dagolden/File-chdir-0.1006/lib/File/chdir.pm


Laurent_R
Veteran / Moderator

Sep 12, 2012, 10:21 AM


Views: 2163
Re: [sreevno] change directory in windows and extract the files from a .zip file inside the folder

Do you really need to change directory? I would probably work directly from the parent directory, to avoid the hassle of going down into one directory, then up again, etc.


kola4help
Novice

Sep 20, 2012, 12:02 PM


Views: 1892
Re: [FishMonger] change directory in windows and extract the files from a .zip file inside the folder

check this.....





chdir("C:\\Perl64\\bin\\extract\\$newdir\\");
system("cazipxp -u $newdir\.caz");