<?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 empty folders issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647416#M193774</link>
    <description>&lt;P&gt;You might have additional &lt;EM&gt;directories&lt;/EM&gt; in there; as posted, my macro only shows &lt;EM&gt;files&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Add another %PUT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %if &amp;amp;subdir ne 0
    %then %do;
      %let subdir=%sysfunc(dclose(&amp;amp;subdir));
      %put dir=&amp;amp;name;
      %find(&amp;amp;name)
    %end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 May 2020 11:32:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-13T11:32:37Z</dc:date>
    <item>
      <title>Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647373#M193742</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have an issue when trying to delete empty folders structure in SAS stored process web application. I'm trying to delete &lt;STRONG&gt;empty&lt;/STRONG&gt; folders:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %macro deleteDirectory(filepath);
        filename testdir "&amp;amp;filepath";
        data _null_;
            rc=fdelete('testdir');
            put rc=;
            msg=sysmsg();
            put msg=;
        run;
        filename testdir clear;
    %mend deleteDirectory;
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/word/_rels);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/word);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and on the second deletion (&amp;amp;_TempFolderPath/docx/word) I receive an error message:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=20047
msg=ERROR: xxx\docx\word is not empty and cannot be deleted.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;_rels directory is removed successfully. I don't have x commands available.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 09:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647373#M193742</guid>
      <dc:creator>bearda</dc:creator>
      <dc:date>2020-05-13T09:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647376#M193743</link>
      <description>&lt;P&gt;Use this macro to traverse the whole directory tree and show all files:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro find(directory);
%local did i name subdir fref fref2;
%let did=%sysfunc(filename(fref,&amp;amp;directory));
%let did=%sysfunc(dopen(&amp;amp;fref));
%if &amp;amp;did ne 0
%then %do;
  %do i = 1 %to %sysfunc(dnum(&amp;amp;did));
    %let name=&amp;amp;directory/%sysfunc(dread(&amp;amp;did,&amp;amp;i));
    %let subdir=%sysfunc(filename(fref2,&amp;amp;name));
    %let subdir=%sysfunc(dopen(&amp;amp;fref2));
    %if &amp;amp;subdir ne 0
    %then %do;
      %let subdir=%sysfunc(dclose(&amp;amp;subdir));
      %find(&amp;amp;name)
    %end;
    %else %put &amp;amp;name;
    %let subdir=%sysfunc(filename(fref2));
  %end;
  %let did=%sysfunc(dclose(&amp;amp;did));
%end;
%let did=%sysfunc(filename(fref));
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 May 2020 09:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647376#M193743</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-13T09:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647379#M193745</link>
      <description>&lt;P&gt;Thank you for the help! It seems like folders are actually deleted&amp;nbsp;&lt;EM&gt;after&amp;nbsp;&lt;/EM&gt;execution. Since folders below are deleted (checked from windows explorer after the execution):&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;docx/_rels&lt;/LI&gt;&lt;LI&gt;docx/docprops&lt;/LI&gt;&lt;LI&gt;docx/word/_rels&lt;/LI&gt;&lt;LI&gt;mht/images&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The whole call goes like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %deleteDirectory(&amp;amp;_TempFolderPath/docx/_rels);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/docProps);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/word/_rels);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/word);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx);
    %deleteDirectory(&amp;amp;_TempFolderPath/mht/images);
    %deleteDirectory(&amp;amp;_TempFolderPath/mht);
    %deleteDirectory(&amp;amp;_TempFolderPath);

%* LOG: ;
%* xxx\docx\word is not empty and cannot be deleted.;
%* xxx\docx is not empty and cannot be deleted. ;
%* xxx\mht is not empty and cannot be deleted. ;
%* xxx is not empty and cannot be deleted. ;

%find(&amp;amp;_TempFolderPath);

%* LOG: ;
xxx/docx/docProps
xxx/docx/word/_rels
xxx/docx/_rels
xxx/mht/images&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 10:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647379#M193745</guid>
      <dc:creator>bearda</dc:creator>
      <dc:date>2020-05-13T10:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647416#M193774</link>
      <description>&lt;P&gt;You might have additional &lt;EM&gt;directories&lt;/EM&gt; in there; as posted, my macro only shows &lt;EM&gt;files&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Add another %PUT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %if &amp;amp;subdir ne 0
    %then %do;
      %let subdir=%sysfunc(dclose(&amp;amp;subdir));
      %put dir=&amp;amp;name;
      %find(&amp;amp;name)
    %end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 May 2020 11:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647416#M193774</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-13T11:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647424#M193780</link>
      <description>&lt;PRE&gt;dir=xxx/docx
xxx/docx/docProps
dir=xxx/docx/word
xxx/docx/word/_rels
xxx/docx/_rels
dir=xxx/mht
xxx/mht/images&lt;/PRE&gt;&lt;P&gt;Thanks again for the reply. Images, _rels and docProps are also folders at least in file explorer. I have checked multiple times the folder structure and folders should be deleted in correct order. Before folder deletion I have a macro executed which removes all the files inside folders and that works as expected. Actual path (xxx) is network folder path.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 11:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647424#M193780</guid>
      <dc:creator>bearda</dc:creator>
      <dc:date>2020-05-13T11:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647429#M193783</link>
      <description>&lt;P&gt;So there is a &lt;EM&gt;file&lt;/EM&gt; called docProps in xxx/docx. This prevents the directory from being deleted. Similar for the others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also keep in mind that the SAS code runs on a server, and what you see in your Windows Explorer might only be your local directory tree on the desktop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 11:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647429#M193783</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-13T11:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647726#M193882</link>
      <description>&lt;P&gt;I found out that if I try to delete the same folder twice the second deletion attempt throws an error about insufficient authorization:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %macro deleteDirectory(filepath);
        filename testdir "&amp;amp;filepath";
        data _null_;
            rc=fdelete('testdir');
            put rc=;
            msg=sysmsg();
            put msg=;
        run;
        filename testdir clear;
    %mend deleteDirectory;
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/_rels);
    %deleteDirectory(&amp;amp;_TempFolderPath/docx/_rels);


LOG:
rc=0
msg= 

rc=20029
msg=ERROR: Insufficient authorization to access xxx\docx\_rels.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So the first deletion actually does not delete the file. There should not be authorization issues.. And if I check afterwards in the same run files with your %find macro the folder still exist.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 08:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647726#M193882</guid>
      <dc:creator>bearda</dc:creator>
      <dc:date>2020-05-14T08:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting empty folders issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647730#M193883</link>
      <description>&lt;P&gt;I think you should put this to the attention of SAS Technical Support, as this makes no sense to me at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only explanation that comes to my mind is that some of the numerous Windows idiosyncrasies play a role here. If your xxx actually points to a UNC or other shared network location, that might also be part of the problem.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 09:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-empty-folders-issue/m-p/647730#M193883</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T09:15:39Z</dc:date>
    </item>
  </channel>
</rss>

