<?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: delete a folder( directory) and all files on it in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584879#M166692</link>
    <description>&lt;P&gt;thank you so much.&lt;/P&gt;
&lt;P&gt;I get an error&amp;nbsp;ERROR: Shell escape is not valid in this SAS session.&lt;BR /&gt;26 X "rm -R /usr/local/SAS/SASUsers/LabRet/UserDir/udclk88/TYOTA"&lt;BR /&gt;26 ! ;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 08:36:52 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-08-29T08:36:52Z</dc:date>
    <item>
      <title>delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584870#M166683</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to&amp;nbsp; delete a folder( directory) that included files.&lt;/P&gt;
&lt;P&gt;In this action I want to delete all files in this folder( directory) and delete the folder( directory) too.&lt;/P&gt;
&lt;P&gt;I know how to do it by delete each file and then delete the directory&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if i have 1000 files then i need to run 1000 procedures and then 1 procedure to delete directory.&lt;/P&gt;
&lt;P&gt;Is there a way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Yakov&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584870#M166683</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-29T08:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584871#M166684</link>
      <description>&lt;P&gt;please use the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'rm -r foldername or path';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584871#M166684</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T08:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584873#M166686</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;I am trying to use the code but get an error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"/Path/Folder1/";&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;The&amp;nbsp; error is&lt;/P&gt;
&lt;P&gt;ERROR: Shell escape is not valid in this SAS session.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584873#M166686</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-29T08:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584874#M166687</link>
      <description>&lt;P&gt;its working for me, i tried the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'rm -r ~path/foldername';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584874#M166687</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T08:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584875#M166688</link>
      <description>&lt;P&gt;This is the path&lt;/P&gt;
&lt;P&gt;"/usr/local/SAS/SASUsers/LabRet/UserDir/udclk88/TYOTA/"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you update the code please and send me ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you so much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584875#M166688</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-29T08:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584876#M166689</link>
      <description>is  the folder to be deleted is TYOTA</description>
      <pubDate>Thu, 29 Aug 2019 08:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584876#M166689</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T08:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584877#M166690</link>
      <description>&lt;P&gt;yes.name of folder to be deleted is &lt;SPAN&gt;TYOTA&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584877#M166690</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-29T08:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584878#M166691</link>
      <description>&lt;P&gt;please try the below code to delete &lt;CODE class=" language-sas"&gt;TYOTA&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X "rm -r /usr/local/SAS/SASUsers/LabRet/UserDir/udclk88/TYOTA";
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584878#M166691</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T08:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584879#M166692</link>
      <description>&lt;P&gt;thank you so much.&lt;/P&gt;
&lt;P&gt;I get an error&amp;nbsp;ERROR: Shell escape is not valid in this SAS session.&lt;BR /&gt;26 X "rm -R /usr/local/SAS/SASUsers/LabRet/UserDir/udclk88/TYOTA"&lt;BR /&gt;26 ! ;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584879#M166692</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-29T08:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584882#M166693</link>
      <description>&lt;P&gt;I believe the X commands are not allowed in your environment. Because of which the X command is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively you need to establish the X command to work. please follow below steps and then try running the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/41/058.html" target="_self"&gt;http://support.sas.com/kb/41/058.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584882#M166693</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T08:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584883#M166694</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;its working for me, i tried the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'rm -r ~path/foldername';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The error indicates that the option noxcmd is active.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp; With xmcd disabled deleting a folder and its contents is somewhat annoying: you have to to use fdelete to delete each file and finally the same function can be used to delete the empty folder. That approach has one major advantage: the code is independent of the sas-servers operating-system. But it is annoying amount of code, so asking the admins why xcmd is disabled seems to be a good first step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the meantime try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let folderToDelete = insert_folder_name_here;

data work.FilesToDelete;
   length Name $ 100;
   keep Name;

   rc = filename("folder", "&amp;amp;folderToDelete.");
   dirId = dopen("folder");

   do i = 1 to dnum(dirID);
      Name = dread(dirId, i);
      output;
   end;

   rc = dclose(dirId);
run;

data _null_;
   set work.FilesToDelete end=lastDeleted;

   put "Deleting " Name;

   rc = filename("delfile", cats("&amp;amp;folderToDelete./", Name));
   rc = fdelete("delfile");
   put "del file " rc=;
   rc = filename("delfile");

   if lastDeleted then do;
      put "Deleting the folder '&amp;amp;folderToDelete.'";
      rc = filename("folder", "&amp;amp;folderToDelete.");
      rc = fdelete("folder");
      put "del folder " rc=;
      rc = filename("folder");
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 08:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584883#M166694</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-29T08:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584885#M166696</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;I am trying to use the code but get an error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"/Path/Folder1/";&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;The&amp;nbsp; error is&lt;/P&gt;
&lt;P&gt;ERROR: Shell escape is not valid in this SAS session.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which means you operate under NOXCMD. This is the default setting of a SAS BI Server installation.&lt;/P&gt;
&lt;P&gt;Either have XCMD enabled by the SAS administrator, or run one of the many codes turned up by a google search for "sas delete all files in a directory".&lt;/P&gt;
&lt;P&gt;The functions to use from a data step are filename() dopen(), dnum(), dread() and fdelete():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
dirname = 'directory path';
dref = 'mydir';
filref = 'myfile';
length fname $200;
rc = filename(dref,dirname);
did = dopen(dref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  rc = filename(filref,catx('/',dirname,fname));
  rc = fdelete(filref);
end;
rc = dclose(did);
rc = fdelete(dref);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this will work only on a one-level directory. If you have further subdirectories in there, the whole thing needs to be done recursively with macro code. And once you've done that, you'll feel the urge to shoot the admin who refused to enable XCMD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Edit: changed the delete for the directory to use the dref.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 09:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584885#M166696</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-29T09:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: delete a folder( directory) and all files on it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584912#M166709</link>
      <description>&lt;P&gt;PS a way to recursively find files in a directory tree with a macro was just posted here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584896" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584896&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I added a method to save the result in a dataset.&lt;/P&gt;
&lt;P&gt;It shouldn't be difficult to develop a data step that deletes the files and, when detecting a change in the directory part of the filename, the directory.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-a-folder-directory-and-all-files-on-it/m-p/584912#M166709</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-29T12:39:46Z</dc:date>
    </item>
  </channel>
</rss>

