DATA Step, Macro, Functions and more

filename zip pipe wrong target path is used

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

filename zip pipe wrong target path is used

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

 

 

 

 


Accepted Solutions
Solution
‎03-01-2018 04:48 PM
Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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


All Replies
Super User
Super User
Posts: 9,427

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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

Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

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

 

Super User
Super User
Posts: 7,935

Re: filename zip pipe wrong target path is used

[ Edited ]
Posted in reply to Billybob73

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 *" ;

 

Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

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 *" ;

Super User
Super User
Posts: 7,935

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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.

Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

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

SAS Employee
Posts: 20

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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

Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

Posted in reply to DaveHorne

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

SAS Employee
Posts: 20

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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

Solution
‎03-01-2018 04:48 PM
Contributor
Posts: 55

Re: filename zip pipe wrong target path is used

Posted in reply to Billybob73

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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