CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

Post #1 of 4 (1205 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.


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

Post #2 of 4 (1201 views)
Re: [sreevno] change directory in windows and extract the files from a .zip file inside the folder [In reply to] Can't Post

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

Post #3 of 4 (1196 views)
Re: [sreevno] change directory in windows and extract the files from a .zip file inside the folder [In reply to] Can't Post

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

Post #4 of 4 (925 views)
Re: [FishMonger] change directory in windows and extract the files from a .zip file inside the folder [In reply to] Can't Post

check this.....





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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives