我有一个代码将文件压缩到一个公共文件中。它的工作原理是将文件添加到zip文件夹中,代码如下所示。但是有一些简单的方法如何压缩整个文件夹,即不是逐个文件?
/*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;
感谢您提出哪些建议。
答案 0 :(得分:3)
没有X command
就可以。
您必须以递归方式读取目录并将所有文件添加到存档中。
出于某种原因ods package
它很慢。
%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)