BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Billybob73
Quartz | Level 8

Hi

I'm not sure if anyone has ever worked with this or if this is the right place to ask this question since it is not really a SAS topic.. but i'll give it a try anyway.

 

I'm running this :

 

filename zip pipe "zip -r c:\temp\accept\test.zip c:\temp\accept/*" ;
data _null_;
infile zip;
input;
put _infile_;
run;

 

And this is working.........

But when I doubleclick on test.zip it appears that the contents of the zip files is in this path :

c:\temp\accept\test.zip\temp\accept

 

This is not what I want.

It  needs to go in  :

 

c:\temp\accept\test.zip

 

How do I change this 'Windows command' to make sure this will happen ?

I've checked the Info-Zip FAQ but cannot find out what to do.

 

Thanks

B

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Billybob73
Quartz | Level 8

Hi,

Just managed to find solution below. The -p parameter did work though, Dave 😉

Thanks everybody

 

x "cd c:\temp\test";
filename zip pipe "zip -r -p split.zip * " ;
data _null_;
infile zip;
input;
put _infile_;
run;

 

Regards

B

View solution in original post

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, thats more of a question for the zip command line people.  A check on the documents reveals this:

-p

 
 

--paths

 

Include relative file paths as part of the names of files stored in the archive. This is the default. The -j option junks the paths and just stores the names of the files.

 

From:

http://www.info-zip.org/mans/zip.html

Billybob73
Quartz | Level 8

Hi,

Thanks. -j works, however this only compresses root folder contents. I need to compress the whole directory structure including files within folders, hence the use of -r in my script. I tried to use both , but this does not work unfortunately.

 

Is this structure possible at all ?

 

zip -j -r foo foo/*

 

in which foo is the directory path

 

Thanks

Regards,

B

 

Tom
Super User Tom
Super User

If you don't want the high level folders in the paths that are included in the ZIP file then don't use them in the command.

So instead of 

filename zip pipe "zip -r c:\temp\accept\test.zip c:\temp\accept/*" ;

You want something more like

filename zip pipe "cd c:\temp\accept; zip -r test.zip *" ;

But you might want to write the ZIP file itself to another folder to prevent it from trying to store a copy of the zip file inside itself.

filename zip pipe "cd c:\temp\accept; zip -r ..\test.zip *" ;

 

Billybob73
Quartz | Level 8

Hi Tom,

Thanks for your suggestion. This sounds very logical, except it doesn't do anything, no zipfiles unfortunately.

Something still is wrong in the syntax.. I tried them with a forward slash right before the *, but no success either..

Regards

B

 

filename zip pipe "cd c:\temp\accept; zip -r test.zip *" ;

filename zip pipe "cd c:\temp\accept; zip -r c:\temp\accept\test.zip *" ;

Tom
Super User Tom
Super User

@Billybob73 wrote:

Hi Tom,

Thanks for your suggestion. This sounds very logical, except it doesn't do anything, no zipfiles unfortunately.

Something still is wrong in the syntax.. I tried them with a forward slash right before the *, but no success either..

Regards

B

 

filename zip pipe "cd c:\temp\accept; zip -r test.zip *" ;

filename zip pipe "cd c:\temp\accept; zip -r c:\temp\accept\test.zip *" ;


Get the commands to work from command window then use them.

You might need to use an X command to run the CD command separately. 

Also I find it useful to use a data _null_ step with piped command do see what messages the command is generating.

data _null_;
  infile 'some command' pipe ;
  input;
  put _infile_;
run;

 

There might be more advanced ZIP options that allow for you to specify what part of path to include in zip file.

Billybob73
Quartz | Level 8

Hi,

I'm sorry but I just do not know how to do this . Also this failed...........

Anyone happens to have this code ?

 

x "c:\temp\accept";
filename zip pipe "zip -r test.zip" ;
data _null_;
infile zip;
input;
put _infile_;
run;

 

Regards,

B

DaveHorne
SAS Employee

You may need to add the -p (or -P) command line option to store the folder names.  From the doc:

WZZIP reference

-p|P Store folder names. A lower case p stores only the names of folders recursed (subfolders included) via the -r option, while an upper case P stores all folder information specified on the command line or in the listfile. Use with the -r option.

In the following examples, assume this folder structure:

  Level1\LevelA
Level1\LevelB

Level1 contains the file file1.txt

Level1\LevelA contains two files, a1.txt and a2.txt

Level1\LevelB contains two files, b1.txt and b2.txt

  wzzip -p -r d:\temp\test.zip d:\level1\*.*

This creates test.zip containing file1.txt, folder Level1\LevelA with files a1.txt and a2.txt, and folder Level1\LevelB with files b1.txt and b2.txt. Note that the folder Level1 itself does not get included.

Extracting from test.zip will create the following files and folders in the extract-to folder:

File1.txt

LevelA\a1.txt

LevelA\a2.txt

LevelB\b1.txt

LevelB\b2.txt

  wzzip -P -r d:\temp\test.zip d:\level1\*.*

This creates test.zip with folder Level1 containing file file1.txt, folder Level1\LevelA containing files a1.txt and a2.txt, and folder Level1\LevelB containing files b1.txt and b2.txt.

Extracting from test.zip will create the following files and folders in the extract-to folder:

Level1\file1.txt

Level1\LevelA\a1.txt

Level1\LevelA\a2.txt

Level1\LevelB\b1.txt

Level1\LevelB\b2.txt

Billybob73
Quartz | Level 8

Hi,

Thanks Dave.

I tried to add the -p but nothing happens unfortunately.

x "c:\temp\test";
filename zip pipe "zip -p -r test.zip" ;
data _null_;
infile zip;
input;
put _infile_;
run;

 

What is wzzip  ? I'm using the zip and unzip commands from Info-Zip.

 

Regards,

B

DaveHorne
SAS Employee

@Billybob73 sorry about that, I was thinking WinZip, which has separate CLI tools, and I see now you are using Info-Zip.

Billybob73
Quartz | Level 8

Hi,

Just managed to find solution below. The -p parameter did work though, Dave 😉

Thanks everybody

 

x "cd c:\temp\test";
filename zip pipe "zip -r -p split.zip * " ;
data _null_;
infile zip;
input;
put _infile_;
run;

 

Regards

B

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1585 views
  • 0 likes
  • 4 in conversation