<?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: deleting files from a folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594847#M171011</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends on what environment your working on. Windows or Unix/Linux. Did you try the X-commands (run system commands from SAS).&lt;/P&gt;
&lt;P&gt;In UNIX/LINUX:&lt;/P&gt;
&lt;PRE class="lang-bsh prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;X "find &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;name &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt; &lt;SPAN class="str"&gt;'DES*'&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;exec rm &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;{}&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; \;";&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In Windows:&lt;/P&gt;
&lt;PRE&gt;X "Get-ChildItem -include DES* -recurse -force | Remove-Item -force";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In some environments (Unix) SAS users are restricted to run commands, in that case you may try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Read files in a folder */

%let path=/user/files;

FILENAME _folder_ "%bquote(&amp;amp;path.)";
data filenames(keep=memname);
  handle=dopen( '_folder_' );
  if handle &amp;gt; 0 then do;
    count=dnum(handle);
    do i=1 to count;
      memname=dread(handle,i);
      if substr(memname,1,3)='Wra' then output filenames;
    end;
  end;
  rc=dclose(handle);
run;
filename _folder_ clear;



/* delete files identified in above step */
data _null_;
set filenames;
fname = 'todelete';
rc = filename(fname, quote(cats("&amp;amp;path",'/',memname)));
rc = fdelete(fname);
rc = filename(fname);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 Oct 2019 18:23:34 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2019-10-08T18:23:34Z</dc:date>
    <item>
      <title>deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594814#M170991</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to delete certain files from a folder?&amp;nbsp; I have a conversion program that creates a bunch of csv files.&amp;nbsp; However, I would like to delete all the files that begin with "DES" since they're not needed.&amp;nbsp; Is there a step I can add to the conversion program to delete the DES files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is truly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 16:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594814#M170991</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2019-10-08T16:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594826#M170997</link>
      <description>FDELETE() will delete a file. Without seeing the rest of your conversion program it's hard to say what is possible.</description>
      <pubDate>Tue, 08 Oct 2019 17:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594826#M170997</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-08T17:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594828#M170999</link>
      <description>Is there a way to say in FDELETE to delete any file that starts with "DES"</description>
      <pubDate>Tue, 08 Oct 2019 17:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594828#M170999</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2019-10-08T17:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594830#M171000</link>
      <description>You can try a wild card, "DES*.txt" and see what happens. That works in other commands....</description>
      <pubDate>Tue, 08 Oct 2019 17:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594830#M171000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-08T17:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594834#M171004</link>
      <description>I'm not familiar with macros or fdelete.  But I found this on the sas website and modified it:&lt;BR /&gt;&lt;BR /&gt;%macro check(file);&lt;BR /&gt;%if %sysfunc(fileexist(&amp;amp;file)) ge 1 %then %do;&lt;BR /&gt;   %let rc=%sysfunc(filename(temp,&amp;amp;file));&lt;BR /&gt;   %let rc=%sysfunc(fdelete(&amp;amp;temp));&lt;BR /&gt;%end; &lt;BR /&gt;%else %put The file &amp;amp;file does not exist;&lt;BR /&gt;%mend check; &lt;BR /&gt;&lt;BR /&gt;%check(C:\Desktop\Excel\DES*.csv)&lt;BR /&gt;&lt;BR /&gt;It didn't work though</description>
      <pubDate>Tue, 08 Oct 2019 18:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594834#M171004</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2019-10-08T18:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594847#M171011</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends on what environment your working on. Windows or Unix/Linux. Did you try the X-commands (run system commands from SAS).&lt;/P&gt;
&lt;P&gt;In UNIX/LINUX:&lt;/P&gt;
&lt;PRE class="lang-bsh prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;X "find &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;name &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt; &lt;SPAN class="str"&gt;'DES*'&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;exec rm &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;{}&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; \;";&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In Windows:&lt;/P&gt;
&lt;PRE&gt;X "Get-ChildItem -include DES* -recurse -force | Remove-Item -force";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In some environments (Unix) SAS users are restricted to run commands, in that case you may try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Read files in a folder */

%let path=/user/files;

FILENAME _folder_ "%bquote(&amp;amp;path.)";
data filenames(keep=memname);
  handle=dopen( '_folder_' );
  if handle &amp;gt; 0 then do;
    count=dnum(handle);
    do i=1 to count;
      memname=dread(handle,i);
      if substr(memname,1,3)='Wra' then output filenames;
    end;
  end;
  rc=dclose(handle);
run;
filename _folder_ clear;



/* delete files identified in above step */
data _null_;
set filenames;
fname = 'todelete';
rc = filename(fname, quote(cats("&amp;amp;path",'/',memname)));
rc = fdelete(fname);
rc = filename(fname);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Oct 2019 18:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594847#M171011</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-10-08T18:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594849#M171012</link>
      <description>1. Lookup the documentation on FDELETE and try deleting a single file&lt;BR /&gt;2. Try deleting a series of files using wildcard&lt;BR /&gt;3. Once it's working, incorporate it into your code.</description>
      <pubDate>Tue, 08 Oct 2019 18:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594849#M171012</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-08T18:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594865#M171017</link>
      <description>&lt;P&gt;It looks like FDELETE() does not support wildcards so you're best off using SYSEXEC() and a command instead. That would be like:&lt;/P&gt;
&lt;P&gt;Be careful with the quotes there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'rm "path to file\DES*.extension"';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Oct 2019 18:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/594865#M171017</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-08T18:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: deleting files from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/915703#M360788</link>
      <description>Thanks Suryakiran. Your code works perfectly fine for me.</description>
      <pubDate>Mon, 12 Feb 2024 21:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-files-from-a-folder/m-p/915703#M360788</guid>
      <dc:creator>Avinash14</dc:creator>
      <dc:date>2024-02-12T21:33:23Z</dc:date>
    </item>
  </channel>
</rss>

