
sreevno
New User
Sep 11, 2012, 9:55 PM
Post #1 of 4
(2250 views)
|
change directory in windows and extract the files from a .zip file inside the folder
|
Can't Post
|
|
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.
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"; }}
|