<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAS code to zip entire directories and keep directory structure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713116#M219943</link>
    <description>&lt;P&gt;Ideal: everything. SAS code, data and created output&amp;nbsp; zipped like it would be if you could just zip it.&amp;nbsp; The files are not large, they are just organized, and students organize their work because I teach them to organize their work, so it would be nice to be able to download and preserve directory structure somehow. SAS On Demand is a cloud version of SAS Studio, file system is Linux as far as I can tell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next:&amp;nbsp; SAS code and data files&lt;/P&gt;&lt;P&gt;Third:&amp;nbsp; At least SAS code&amp;nbsp; (I would take this as I have SAS locally so I could always just regenerate things but this is not ideal for students, although students who go on and use SAS in other platforms would at least have their code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The real problem I am trying to solve is that if you work on SAS OnDemand there is no functionality to download more than one file at a time, so I thought one way to archive files would be to zip all the files into a zip file, then you could download the zip file.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2021 16:27:12 GMT</pubDate>
    <dc:creator>LauraRK</dc:creator>
    <dc:date>2021-01-21T16:27:12Z</dc:date>
    <item>
      <title>SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713036#M219917</link>
      <description>&lt;P&gt;I used SAS OnDemand for Academics this semester in my teaching.&amp;nbsp; I created a lot of examples and put them in named directories, but I just learned that I can't download my work except for one file at a time.&amp;nbsp; Given the system I can't use pipes.&lt;/P&gt;&lt;P&gt;Is it possible within SAS studio to put an entire folder and its subfolder into a zip file preserving the directory structure using SAS.&amp;nbsp; I can figure out how to zip one file but can't figure this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 11:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713036#M219917</guid>
      <dc:creator>LauraRK</dc:creator>
      <dc:date>2021-01-21T11:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713111#M219940</link>
      <description>&lt;P&gt;What type of files are we discussing? Program files? Data sets? ODS Documents? All of these?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 16:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713111#M219940</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-21T16:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713116#M219943</link>
      <description>&lt;P&gt;Ideal: everything. SAS code, data and created output&amp;nbsp; zipped like it would be if you could just zip it.&amp;nbsp; The files are not large, they are just organized, and students organize their work because I teach them to organize their work, so it would be nice to be able to download and preserve directory structure somehow. SAS On Demand is a cloud version of SAS Studio, file system is Linux as far as I can tell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next:&amp;nbsp; SAS code and data files&lt;/P&gt;&lt;P&gt;Third:&amp;nbsp; At least SAS code&amp;nbsp; (I would take this as I have SAS locally so I could always just regenerate things but this is not ideal for students, although students who go on and use SAS in other platforms would at least have their code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The real problem I am trying to solve is that if you work on SAS OnDemand there is no functionality to download more than one file at a time, so I thought one way to archive files would be to zip all the files into a zip file, then you could download the zip file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 16:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713116#M219943</guid>
      <dc:creator>LauraRK</dc:creator>
      <dc:date>2021-01-21T16:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713124#M219945</link>
      <description>&lt;P&gt;Someone already posted the answer on your other thread.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Analytics-U/Bulk-Download-all-my-files-from-SAS-Ondemand/m-p/712727#M9948" target="_blank"&gt;https://communities.sas.com/t5/SAS-Analytics-U/Bulk-Download-all-my-files-from-SAS-Ondemand/m-p/712727#M9948&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 16:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/713124#M219945</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-21T16:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/759516#M240028</link>
      <description>For some reason when I click on this solution I can't see the post, can others see it? I get permission denied.</description>
      <pubDate>Wed, 04 Aug 2021 21:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/759516#M240028</guid>
      <dc:creator>LauraRK</dc:creator>
      <dc:date>2021-08-04T21:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/823235#M325054</link>
      <description>&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/41872561/sas-zipping-folder" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/41872561/sas-zipping-folder&lt;/A&gt;&amp;nbsp; was a helpful answer.&amp;nbsp; I pasted the code below so that if the post goes away it will be here.&amp;nbsp; For SAS OD you need to fix the slashes for the directories.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let n=0;
%macro readCatalog(path, localpath);
    %local rc _path filrf did noe filename fid i;

    %if &amp;amp;localpath = %then
        %let _path=&amp;amp;path;
    %else 
        %let _path=&amp;amp;path\&amp;amp;localpath;

    %let n=%eval(&amp;amp;n+1);
    %let filrf=DIR&amp;amp;n;

    %let rc = %sysfunc(filename(filrf, &amp;amp;_path));
    %let did = %sysfunc(dopen(&amp;amp;filrf));
    %let noe = %sysfunc(dnum(&amp;amp;did));

    %do i = 1 %to &amp;amp;noe;
        %let filename = %bquote(%sysfunc(dread(&amp;amp;did, &amp;amp;i)));
        %let fid = %sysfunc(mopen(&amp;amp;did, &amp;amp;filename));
        %if &amp;amp;fid &amp;gt; 0 %then %do;
            %put &amp;amp;=path &amp;amp;=localpath &amp;amp;=_path &amp;amp;=filename;
            ods package(newzip) add file="&amp;amp;_path\&amp;amp;filename" path="&amp;amp;localpath";
        %end;
        %else %do;
            %if &amp;amp;localpath = %then
                %readCatalog(&amp;amp;path, &amp;amp;filename);
            %else 
                %readCatalog(&amp;amp;path, &amp;amp;localpath\&amp;amp;filename);
        %end;
    %end;
    %let rc=%sysfunc(dclose(&amp;amp;did));
%mend readCatalog;

%macro createZIP(path, archive_name, archive_path);
    %put *** Creating an archive (&amp;amp;archive_path\&amp;amp;archive_name) ***;
    ods package(newzip) open nopf;
    %readCatalog(&amp;amp;path)
    ods package(newzip) publish archive properties(
        archive_name="&amp;amp;archive_name" 
        archive_path="&amp;amp;archive_path"
    );
    ods package(newzip) close;
%mend createZIP;

%createZIP(C:\temp, test.zip, C:\temp2)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jul 2022 21:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/823235#M325054</guid>
      <dc:creator>LauraRK</dc:creator>
      <dc:date>2022-07-13T21:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to zip entire directories and keep directory structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/823245#M325060</link>
      <description>&lt;P&gt;They must have moved the post or changed the way the links work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the list of files into a dataset.&amp;nbsp; Use the dataset to generate FCOPY() function calls to copy the files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example using the &lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_self"&gt;%DIRTREE()&lt;/A&gt; macro to get the list of files.&lt;/P&gt;
&lt;P&gt;So first make sure you have the macro defined.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dirtree url "https://raw.githubusercontent.com/sasutils/macros/master/dirtree.sas";
%include dirtree;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then setup macro variables to point to the source directory and the target file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let inpath=c:\project\template ;
%let outfile=c:\project\template.zip ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use the %DIRTREE() macro to get the list and then use a data step to generate an input and output fileref and call the FCOPY() function to copy them.&amp;nbsp; &amp;nbsp;I like to use RECFM=F and LRECL=512 to copy files as BINARY.&amp;nbsp; I am not sure how to create empty folders, so just ignore the records in the output of %DIRTREE() that are for directories.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%dirtree(&amp;amp;inpath)

data _null_;
   if eof then put 'NOTE: copied ' ncopied 'files from ' "'&amp;amp;inpath'" ' to ' "'&amp;amp;outfile'.";
   set dirtree end=eof;
   where type ne 'D' ;
   length in out $8 target msg $256;
   target=translate(catx('/',substrn(path,length("&amp;amp;inpath")+2),filename),'/','\');
   rc1=filename(in,catx('/',path,filename),'disk','recfm=f lrecl=512');
   rc2=filename(out,"&amp;amp;outfile",'zip',catx(' ','recfm=f lrecl=512',cats('member=',quote(trim(target),"'")))) ;
   rc3=fcopy(in,out);
   if rc3 then do;
     msg=sysmsg();
     put (_n_ rc: target msg) (=);
   end;
   else ncopied+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 02:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-zip-entire-directories-and-keep-directory-structure/m-p/823245#M325060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-14T02:55:44Z</dc:date>
    </item>
  </channel>
</rss>

