Date: Sat, 27 Sep 2008 08:18:34 +0200
Reply-To: Rune Runnestø <rune@FASTLANE.NO>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Rune Runnestø <rune@FASTLANE.NO>
Subject: Re: Macro to delete all files in a folder
Thanks to Dave for his justification of the code. Here is the result. I have
submitted it and it works.
%macro delete_all_files_in_folder(folder);
options noxwait;
filename xlfile pipe "dir ""&folder"" /b" lrecl=200;
data _null_;
infile xlfile length=len end = eof ;
input char $varying200. len;
run;
x "del /f/q &folder" ;
x dir;
%mend;
%delete_all_files_in_folder(d:\temp)
However, I think I will prefer this one. Because it is more "calm" then the
other. "Calm" in the sense of the world that the xwindows do not flap over
the display unit.
%macro delete_all_the_files_in_folder(folder);
filename filelist "&folder";
data _null_;
dir_id = dopen('filelist');
total_members = dnum(dir_id);
do i = 1 to total_members; /* walk through all the files in the
folder */
member_name = dread(dir_id,i);
file_id = mopen(dir_id,member_name,'i',0);
if file_id > 0 then do; /* if the file is readable */
freadrc = fread(file_id);
rc = fclose(file_id);
rc = filename('delete',member_name,,,'filelist');
rc = fdelete('delete');
end;
rc = fclose(file_id);
end;
rc = dclose(dir_id);
run;
%mend;
%delete_all_the_files_in_folder(d:\temp)
Rune
|