- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is it possible to delete a complete folder with files in it with one singe statement ?
Or do you first need to remove the files and then the folders ?
Thanks
B
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Example 2:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245893.htm
Do be careful, there is no way back though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The fdelete() function (which is the SAS tool for this) can only remove empty directories. Removing a non-empty directory will require XCMD and the proper command from the OS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Well, you could combine the first example, with a loop over dir and then a delete folder:
https://amadeus.co.uk/sas-tips/listing-files-in-a-directory/
So take the second box, replace the put line with an:
rc=fdelete(physname);
Possibly need path as well - can't check at the moment. Then at the end fdelete the folder.
Not saying its ideal at any rate, but it is possible with just SAS functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I combined both, but there's still a problem that remains. Folders which did not have files in them were not deleted.
General question : How can I delete empty folders with empty sub folders from SAS ? Is this possible ?
I tried x commands but they don't work despite path authorization and XCMD switched on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just saying "it doesn't work" does not help at all. Please show examples of what code you have tried.
With the X command ones, likelihood is what you sent to the operating system was incorrect. Again. code would show this. Also note, that the commands for windows are different to linux/unix or other OS's.
Also out of interest, why do you want to do this, sounds more like a sys admin role than a SAS programming one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You're right about that. I've been assigned as sysadmin to get listings of files for our sas user community.
I'm running this :
%let path = %nrstr(G:\TEST\R&D);
options noxwait ;
x "rmdir &path. /s /q";
options xwait;
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then not sure why you are doing this in SAS? Anyways, something umped out at me
%let path = %nrstr(G:\TEST\R&D);
^
Yep, good old special characters in a system path. Bad, bad, bad.
What happens when you run the code, can you run it with /q off and see what the system error is? I suspect either the & is messing with macro resolution, or you lack some sort of permission/that folder doesn't exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The & is the reason I'm using a %nrstr
I've made some progress, but still not working unfo..
%let path=%nrstr(G:\TEST\R&D);
options noxsync noxwait noxmin;
x rd /S /Q "&path";
options xwait;
something in the syntax is still not right........
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Instead of the x statement, use the filename pipe method:
filename oscmd pipe "rd /S /Q '&path' 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
This will show all output and messages in the SAS log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kurt,
Thanks
Unfortunately this is not working
Rgds
B
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"not working" is very un-helpful.
Please post the log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kurt,
I found out that this is working :
options noxsync noxwait noxmin;
x RD /S /Q "%superq(folderdelete)";
options xwait;
Thanks to your hints I managed to do this 🙂
Rgds,
B
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
By the way folderdelete is a macro variable that comes from a do loop. This is the loop code :
%let max_id = 0;
proc sql noprint; select max(id) into:max_id from deleterootfolders2; quit;
%put &max_id.;
%if %eval(&max_id.) ne 0 %then
%do;
%do a=1 %to &max_id.;
data _null_;
set deleterootfolders2;
call symputx('folderdelete', year_root);
where ID = &&a.;
run;
options noxsync noxwait noxmin;
x RD /S /Q "%superq(folderdelete)";
options xwait;
%end;
%end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I used these. Rather than x commands. Thanks !