<?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: How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in S in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862077#M340509</link>
    <description>&lt;P&gt;External commands (through X statement, SYSTEM function, CALL SYSTEM, %SYSEXEC, INFILE PIPE) can only be used if the XCMD system option is set. If NOXCMD is set (default for BI Server installations), you must rely on the SAS functions.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2023 07:25:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-03-03T07:25:18Z</dc:date>
    <item>
      <title>How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862068#M340504</link>
      <description>&lt;P&gt;&amp;nbsp;I found the code to delete specific type of files using the sas code; just curious can we remove the files from the folder using the CMD codes in SAS?&lt;/P&gt;
&lt;P&gt;Reference to remove using SSAS code :&lt;A href="https://stackoverflow.com/questions/23160177/sas-delete-all-txt-files-in-a-folder" target="_blank"&gt;https://stackoverflow.com/questions/23160177/sas-delete-all-txt-files-in-a-folder&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 03:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862068#M340504</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-03T03:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862077#M340509</link>
      <description>&lt;P&gt;External commands (through X statement, SYSTEM function, CALL SYSTEM, %SYSEXEC, INFILE PIPE) can only be used if the XCMD system option is set. If NOXCMD is set (default for BI Server installations), you must rely on the SAS functions.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 07:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862077#M340509</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-03T07:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862086#M340516</link>
      <description>&lt;P&gt;I suggest you to use code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s&amp;nbsp;"Talking to Your Host" article from WUSS 2022 (&lt;A href="https://communities.sas.com/t5/SAS-User-Groups-Library/WUSS-Presentation-Talking-to-Your-Host/ta-p/838344" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-User-Groups-Library/WUSS-Presentation-Talking-to-Your-Host/ta-p/838344&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;The code would be like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* location of a directory */

%let filesLocation=C:\SAS_WORK\;

/* get full list of files with given extension from &amp;amp;filesLocation. (including all subdirectories) */
data files_to_delete; /* just to be sure the file "files"  is "empty" */
run;

data files_to_delete;
  length root dname $ 2048 filename $ 256 dir level 8;
  root = "&amp;amp;filesLocation.";
  retain filename dname ' ' level 0 dir 1;
  label 
    filename = "file"
    dname = "folder"
    ;
run;

data files_to_delete;
  modify files_to_delete;
  rc1=filename('tmp',catx('/',root,dname,filename));
  rc2=dopen('tmp');
  dir = 1 &amp;amp; rc2;
  if dir then 
    do;
      dname=catx('/',dname,filename);
      filename=' ';
    end;
  replace;

  if dir;

  level=level+1;

  do i=1 to dnum(rc2);
    filename=dread(rc2,i);
    if upcase(scan(filename,-1,"."))="EXTENSION_TO_DROP" then output; /* filter out data by Extension_TO_DROP */
  end;
  rc3=dclose(rc2); 
run;

/* Use code from the FDELETE() function documentation to Delete Files */
data _null_;
  set files_to_delete;
  fname="tempfile";
  rc=filename(fname, catx('/',root,dname,filename));
  if rc = 0 and fexist(fname) then
     rc=fdelete(fname);
  rc=filename(fname);
run;
&lt;/CODE&gt;&lt;/PRE&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 09:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/862086#M340516</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-03T09:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/864061#M341252</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 14:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/864061#M341252</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-14T14:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete the specific type of Files ( say  all .txt) files from a folder using the CMD in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/864063#M341254</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 14:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-the-specific-type-of-Files-say-all-txt-files-from/m-p/864063#M341254</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-14T14:06:15Z</dc:date>
    </item>
  </channel>
</rss>

