<?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: Move multiple files from one directory to another. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499667#M72563</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of using filename STATEMENT I suggest to use filename() FUNCTION &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Code is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* assuming that files and folders exist */
data W47XXFM;
input file_name $ : 20.;
cards;
test.pdf
test1.pdf
test2.pdf
;
run;
 

Proc sort data=work.W47XXFM
out =loop (keep= file_name);
by file_name;
run;


options msglevel=i;

data _null_;
set loop;

length msg $ 384;
i=filename('ii', 'C:\SAS_WORK\input\' || strip(file_name), "DISK", "RECFM=N");
o=filename('oo', 'C:\SAS_WORK\output\' || strip(file_name), "DISK", "RECFM=N");
rc=fcopy('ii', 'oo');
if rc=0 then
put 'Copied _bcin to _bcout.';
else do;
msg=sysmsg();
put rc= msg=;
end;

i=filename('ii');
o=filename('oo');

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Sep 2018 19:00:48 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2018-09-27T19:00:48Z</dc:date>
    <item>
      <title>Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499646#M72557</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking to move multiple file from one directory to another directory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column input file saying file names : file_name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input file:- file_name&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;test.pdf&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; test1.pdf&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;test2.pdf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sort data=work.W47XXFM&lt;BR /&gt;out =loop (keep= file_name);&lt;BR /&gt;by &lt;SPAN&gt;file_name&lt;/SPAN&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*1. Move the attachment file */&lt;BR /&gt;data _null_;&lt;BR /&gt;set loop;&lt;BR /&gt;call execute(cats('%Let file= ',&lt;SPAN&gt;file_name&lt;/SPAN&gt;, ' ;'));&lt;/P&gt;&lt;P&gt;filename _bcin "/data/input/&amp;amp;file" RECFM=N;/* RECFM=N needed for a binary copy */;&lt;BR /&gt;filename _bcout "/data/output/&amp;amp;file" RECFM=N;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length msg $ 384;&lt;BR /&gt;rc=fcopy('_bcin', '_bcout');&lt;BR /&gt;if rc=0 then&lt;BR /&gt;put 'Copied _bcin to _bcout.';&lt;BR /&gt;else do;&lt;BR /&gt;msg=sysmsg();&lt;BR /&gt;put rc= msg=;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;filename _bcin clear;&lt;BR /&gt;filename _bcout clear;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it's moving only first file (test.pdf). What to be modified to get all all the files moved?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499646#M72557</guid>
      <dc:creator>ashna</dc:creator>
      <dc:date>2018-09-27T18:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499657#M72558</link>
      <description>&lt;P&gt;Are you using SAS 9.4?&amp;nbsp; If so, &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;the FCOPY function&lt;/A&gt; might be able to do what you need.&amp;nbsp; You still need to copy each file, but you don't need that business with the binary read/binary write.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499657#M72558</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-09-27T18:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499658#M72559</link>
      <description>&lt;P&gt;Instead of filename statements, use the FILENAME function to create references for each file within the data step. Then for FCOPY pass those references. It will work for every line of data listed - you don't need any macros here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235800"&gt;@ashna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking to move multiple file from one directory to another directory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a column input file saying file names : file_name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input file:- file_name&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;test.pdf&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; test1.pdf&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;test2.pdf&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sort data=work.W47XXFM&lt;BR /&gt;out =loop (keep= file_name);&lt;BR /&gt;by &lt;SPAN&gt;file_name&lt;/SPAN&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/*1. Move the attachment file */&lt;BR /&gt;data _null_;&lt;BR /&gt;set loop;&lt;BR /&gt;call execute(cats('%Let file= ',&lt;SPAN&gt;file_name&lt;/SPAN&gt;, ' ;'));&lt;/P&gt;
&lt;P&gt;filename _bcin "/data/input/&amp;amp;file" RECFM=N;/* RECFM=N needed for a binary copy */;&lt;BR /&gt;filename _bcout "/data/output/&amp;amp;file" RECFM=N;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;length msg $ 384;&lt;BR /&gt;rc=fcopy('_bcin', '_bcout');&lt;BR /&gt;if rc=0 then&lt;BR /&gt;put 'Copied _bcin to _bcout.';&lt;BR /&gt;else do;&lt;BR /&gt;msg=sysmsg();&lt;BR /&gt;put rc= msg=;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;filename _bcin clear;&lt;BR /&gt;filename _bcout clear;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's moving only first file (test.pdf). What to be modified to get all all the files moved?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499658#M72559</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-27T18:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499659#M72560</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set work.w47xxfm; *list of files;

x=filename function here;
y=filename function here;

length msg $ 384;
rc=fcopy(x, y);
if rc=0 then
put file_name ' Successfully Copied';
else do;
msg=sysmsg();
put rc= msg=;
end;


run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499659#M72560</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-27T18:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499664#M72561</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm usind SAS DI 4.9.&amp;nbsp;&lt;BR /&gt;Can that cause the&amp;nbsp; problem?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499664#M72561</guid>
      <dc:creator>ashna</dc:creator>
      <dc:date>2018-09-27T18:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499665#M72562</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235800"&gt;@ashna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;HI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm usind SAS DI 4.9.&amp;nbsp;&lt;BR /&gt;Can that cause the&amp;nbsp; problem?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What's the problem? Is the file corrupt?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 19:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499665#M72562</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-27T19:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files from one directory to another.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499667#M72563</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of using filename STATEMENT I suggest to use filename() FUNCTION &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Code is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* assuming that files and folders exist */
data W47XXFM;
input file_name $ : 20.;
cards;
test.pdf
test1.pdf
test2.pdf
;
run;
 

Proc sort data=work.W47XXFM
out =loop (keep= file_name);
by file_name;
run;


options msglevel=i;

data _null_;
set loop;

length msg $ 384;
i=filename('ii', 'C:\SAS_WORK\input\' || strip(file_name), "DISK", "RECFM=N");
o=filename('oo', 'C:\SAS_WORK\output\' || strip(file_name), "DISK", "RECFM=N");
rc=fcopy('ii', 'oo');
if rc=0 then
put 'Copied _bcin to _bcout.';
else do;
msg=sysmsg();
put rc= msg=;
end;

i=filename('ii');
o=filename('oo');

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2018 19:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Move-multiple-files-from-one-directory-to-another/m-p/499667#M72563</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2018-09-27T19:00:48Z</dc:date>
    </item>
  </channel>
</rss>

