- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is there a way to delete certain files from a folder? I have a conversion program that creates a bunch of csv files. However, I would like to delete all the files that begin with "DES" since they're not needed. Is there a step I can add to the conversion program to delete the DES files?
Any help is truly appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%macro check(file);
%if %sysfunc(fileexist(&file)) ge 1 %then %do;
%let rc=%sysfunc(filename(temp,&file));
%let rc=%sysfunc(fdelete(&temp));
%end;
%else %put The file &file does not exist;
%mend check;
%check(C:\Desktop\Excel\DES*.csv)
It didn't work though
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
2. Try deleting a series of files using wildcard
3. Once it's working, incorporate it into your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It depends on what environment your working on. Windows or Unix/Linux. Did you try the X-commands (run system commands from SAS).
In UNIX/LINUX:
X "find -name . 'DES*' -exec rm {} \;";
In Windows:
X "Get-ChildItem -include DES* -recurse -force | Remove-Item -force";
In some environments (Unix) SAS users are restricted to run commands, in that case you may try:
/* Read files in a folder */
%let path=/user/files;
FILENAME _folder_ "%bquote(&path.)";
data filenames(keep=memname);
handle=dopen( '_folder_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
if substr(memname,1,3)='Wra' then output filenames;
end;
end;
rc=dclose(handle);
run;
filename _folder_ clear;
/* delete files identified in above step */
data _null_;
set filenames;
fname = 'todelete';
rc = filename(fname, quote(cats("&path",'/',memname)));
rc = fdelete(fname);
rc = filename(fname);
run;
Suryakiran
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It looks like FDELETE() does not support wildcards so you're best off using SYSEXEC() and a command instead. That would be like:
Be careful with the quotes there.
x 'rm "path to file\DES*.extension"';