Reputation: 159
I have a code that is zipping files into one common file. It works by adding files into the zip folder and the code is provided below. But is there some simple way how to zip the whole folder, i.e. not file by file ?
/*path and files to be zipped*/
%let projectDir = C:\JJ\POKUS_II\data\;
filename newpdf "&projectDir./pokus.pdf";
filename newrtf "&projectDir./pokus.rtf";
filename newxlsx "&projectDir./pokus.xlsx";
/* Creating a ZIP file with ODS PACKAGE */
ods package(newzip) open nopf;
/*which files to zip*/
ods package(newzip) add file=newpdf;
ods package(newzip) add file=newrtf;
ods package(newzip) add file=newxlsx;
/*where to zip*/
ods package(newzip) publish archive
properties(
archive_name="archiv.zip"
archive_path="&projectDir."
);
ods package(newzip) close;
Thank you for suggestions which way to go.
Upvotes: 1
Views: 2191
Reputation: 1188
It is possible without X command
.
You have to read a catalog recursivly and add all files to the archive.
For some reason ods package
it's very slow.
%let n=0;
%macro readCatalog(path, localpath);
%local rc _path filrf did noe filename fid i;
%if &localpath = %then
%let _path=&path;
%else
%let _path=&path\&localpath;
%let n=%eval(&n+1);
%let filrf=DIR&n;
%let rc = %sysfunc(filename(filrf, &_path));
%let did = %sysfunc(dopen(&filrf));
%let noe = %sysfunc(dnum(&did));
%do i = 1 %to &noe;
%let filename = %bquote(%sysfunc(dread(&did, &i)));
%let fid = %sysfunc(mopen(&did, &filename));
%if &fid > 0 %then %do;
%put &=path &=localpath &=_path &=filename;
ods package(newzip) add file="&_path\&filename" path="&localpath";
%end;
%else %do;
%if &localpath = %then
%readCatalog(&path, &filename);
%else
%readCatalog(&path, &localpath\&filename);
%end;
%end;
%let rc=%sysfunc(dclose(&did));
%mend readCatalog;
%macro createZIP(path, archive_name, archive_path);
%put *** Creating an archive (&archive_path\&archive_name) ***;
ods package(newzip) open nopf;
%readCatalog(&path)
ods package(newzip) publish archive properties(
archive_name="&archive_name"
archive_path="&archive_path"
);
ods package(newzip) close;
%mend createZIP;
%createZIP(C:\temp, test.zip, C:\temp2)
Upvotes: 3