<?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: Copying multiple files from 1 drive to another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488829#M127466</link>
    <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;I will try this tom and will let you know. Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 11:43:59 GMT</pubDate>
    <dc:creator>BIDD</dc:creator>
    <dc:date>2018-08-22T11:43:59Z</dc:date>
    <item>
      <title>Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488819#M127458</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Is there any syntax without using X Copy to move files from 1 drive to another? Due to security reason IT security advised me not to use windows based command ( X copy). I have a new requirement now where in I have to transfer over 100 different formatted files (rtf,xls,txt,csv) in 1 go from 1 drive to another.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did google search and got this code, this code is creating copies in same folder by adding _new to the original file names.&lt;/P&gt;&lt;P&gt;Not sure how to amend this code to dump all the files to in to another drive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;let source=P:\Projects\Submissions\DEET18;
%macro directorylisting

  ( path   =   , outdsn = dirlist  , where =     , after  = 01Jan1960  ) ;

  data &amp;amp;outdsn. ( keep = filename fullfilename created modified bytes ) ;
    attrib

      dref         length = $8

      fref         length = $8

      folder       length = $256

      filename     length = $128 label = 'Filename'

      fullfilename length = $256 label = 'Full Filename'

      created      length = 8    label = 'Created'   format = datetime19.

      modified     length = 8    label = 'Modified'  format = datetime19.

      bytes        length = 8    label = 'Bytes'     format = comma15. ;


    if fileexist( "&amp;amp;path." ) then do ;

      folder = ifc( substr( "&amp;amp;path.", lengthn( "&amp;amp;path." ), 1 ) = "\"

        , "&amp;amp;path.", cats( "&amp;amp;path.", "\" ) ) ;

      rc     = filename( dref, folder );

      did    = dopen( dref ) ;

      dcount = dnum( did ) ;


      do i = 1 to dcount ;

        filename = dread( did, i ) ;

      

        if find( filename, "&amp;amp;where.", 'i' ) &amp;gt; 0 then do ;

          fullfilename = cats( folder, filename ) ;

          rc  = filename( fref, fullfilename ) ;

          fid = fopen( fref ) ;

          modified = input( finfo( fid, 'Last Modified' ), anydtdtm. ) ;

          if datepart( modified ) &amp;gt;= "&amp;amp;after."d then do ;

            created = input( finfo( fid, 'Create Time' ), anydtdtm. ) ;

            bytes   = input( finfo( fid, 'File Size (bytes)' ), 18. ) ;

            output ;

          end ;

          fid = fclose( fid ) ;

          rc  = filename( fref, '' ) ;

        end ;

      end ;


      did = dclose( did ) ;

      rc  = filename( dref, '' ) ;

    end ;

    else put "ERROR: The folder &amp;amp;path. does not exist." ;

  run ;

%mend ;
 
%directorylisting(path=&amp;amp;source);

%macro aa;

 data _null_; 

  set dirlist; 

  pos1=index(filename,'.');

  fname1="&amp;amp;source"||'\'||filename; 

  new_fname="&amp;amp;source"||'\'||substr(filename,1,pos1-1)||'_new'||substr(filename,pos1);   

  call symput('file'||strip(_n_), '"'||strip(fname1)||'"'); 

  call symput('new_file'||strip(_n_),'"'||strip(new_fname)||'"');

  call symput('cnt1',_n_);

run;

%do ii = 1 %to &amp;amp;cnt1;

     %put &amp;amp;&amp;amp;file&amp;amp;ii=;

   %put &amp;amp;&amp;amp;new_file&amp;amp;ii=;
   /* these IN and OUT filerefs can point to anything */

    filename in &amp;amp;&amp;amp;file&amp;amp;ii;

    filename out &amp;amp;&amp;amp;new_file&amp;amp;ii;
   /* copy the file byte-for-byte  */

  data _null_;

    length filein 8 fileid 8;

    filein = fopen('in','I',1,'B');

    fileid = fopen('out','O',1,'B');

    rec = '20'x;

    do while(fread(filein)=0);

      rc = fget(filein,rec,1);

      rc = fput(fileid, rec);

      rc =fwrite(fileid);

    end;

    rc = fclose(filein);

    rc = fclose(fileid);

  run;

  filename in clear;

  filename out clear;
  
%mend;


%mend aa;

%aa;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is much appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 11:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488819#M127458</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2018-08-22T11:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488820#M127459</link>
      <description>&lt;P&gt;xcopy is part of the Windows operating system. If you don't trust it, get rid of Windows altogether.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your so-called "security guys" seem to belong to the kind of people that Torvalds ranted about quite recently: &lt;A href="https://plus.google.com/+LinusTorvalds/posts/PeFp4zYWY46" target="_blank"&gt;https://plus.google.com/+LinusTorvalds/posts/PeFp4zYWY46&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 10:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488820#M127459</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-22T10:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488821#M127460</link>
      <description>&lt;P&gt;Ask your IT security group to securely copy the files across for you.&amp;nbsp; Its not really the job of analysis software to do operating system functions.&amp;nbsp; Thats not to say you can't, but I wouldn't advise it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You of course would then want to validate the copy to ensure it is identical etc.&amp;nbsp; Whereas IT will have copy tools (life teracopy) which check the crc of the two files to ensure they are the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In much the same reason as your IT suggested it could be a security risk sending out OS commands (and I can understand that as copying the wrong files, or doing other inadvertent actions could damage your system), doing them through a tool not designed for it is also risky.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 10:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488821#M127460</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T10:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488825#M127463</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt; wrote a blog post a few years back with a data step that could copy files. Simply wrap this in a macro and job is done.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;A caveat with this is it will be slow. The reads/writes are done byte by byte. For relatively small files this is a perfectly usable method to move the data around though.</description>
      <pubDate>Wed, 22 Aug 2018 11:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488825#M127463</guid>
      <dc:creator>SimonDawson</dc:creator>
      <dc:date>2018-08-22T11:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488828#M127465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I tried my best to educate them, but its of no use. only option left for me now is to amend it.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 11:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488828#M127465</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2018-08-22T11:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488829#M127466</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;I will try this tom and will let you know. Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 11:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488829#M127466</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2018-08-22T11:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488832#M127467</link>
      <description>&lt;P&gt;Well, if they only let you have a pocketknife instead of a spanner to change the wheels, let &lt;EM&gt;them&lt;/EM&gt; do it and have all the fun.&lt;/P&gt;
&lt;P&gt;It's my favorite method of disarming know-nothing loudmouth idiots: "If you know better, then show me!"&lt;/P&gt;
&lt;P&gt;I really relish the ensuing sound of silence, and the sheepish looks.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 11:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488832#M127467</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-22T11:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488839#M127470</link>
      <description>&lt;P&gt;SAS 9.4 also &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;locale=en" target="_self"&gt;supports the FCOPY function&lt;/A&gt;, which might do the job.&amp;nbsp; You still need to assemble the list of source/target files, but it's better than the byte-by-byte copy.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 12:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488839#M127470</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-08-22T12:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488851#M127477</link>
      <description>&lt;P&gt;Another question: do you &lt;EM&gt;have&lt;/EM&gt; to do it in SAS?&lt;/P&gt;
&lt;P&gt;Usually, such tasks should be handled by central scheduling and the datacenter people running it. If you do the selection logic in SAS, write a list to a flat file and let the DC people handle the copy/move.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 12:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488851#M127477</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-22T12:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Copying multiple files from 1 drive to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488930#M127519</link>
      <description>&lt;P&gt;1. Get a list of files that need to be copied, stored in a data set&lt;/P&gt;
&lt;P&gt;2. Use FCOPY to copy the file from one location to another&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1 is trivial and I think you can modify the code yourself, if not, check the SAS Macro appendix for a program to list all files in a folder.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Then use FCOPY to move the files over within a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data move_demo;
set file_list; *list of files to be moved;

dir1='path to directory where files are stored'; 
dir2='path to directory where files are to be moved';


rc = fcopy(catx('\', dir1, filename1), catx('\', dir2, filename1));


run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 15:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-multiple-files-from-1-drive-to-another/m-p/488930#M127519</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-22T15:23:14Z</dc:date>
    </item>
  </channel>
</rss>

