Hi,
In a previous question I asked how to list all files (of a certain type) from a directory and all of its subdirectories. Now what I would like is to list all files of all types. I tried to do a small modification to Patrick's code:
%macro list_files(dir);
%local filrf rc did memcnt name i;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
%if &did eq 0 %then %do;
%put Directory &dir cannot be open or does not exist;
%return;
%end;
%do i = 1 %to %sysfunc(dnum(&did));
%let name=%qsysfunc(dread(&did,&i));
%if %sysfunc(findw(%qscan(&name,-1,\),.)) ne 0 %then %do;
data _tmp;
length dir $512 name $100;
dir=symget("dir");
name=symget("name");
run;
proc append base=want data=_tmp;
run;quit;
%end;
%else %if %qscan(&name,2,.) = %then %do;
%list_files(&dir\&name)
%end;
%end;
%let rc=%sysfunc(dclose(&did));
%let rc=%sysfunc(filename(filrf));
%mend list_files;
%list_files(C:\Documents and Settings\HP_Administrator\Desktop\files)
Here I omitted theextension parameter becasue I want all files of all extensions, and the I did a slight modification to the 2nd if:
%if %sysfunc(findw(%qscan(&name,-1,\),.)) ne 0 %then %do;
So I want to scan the name starting fromt the right and extracting the substring until the first '\', and within this substring I want to find a '.' (dot) which signals that it is an extension. But when I ran the macro I didn't get any table at all. Tried different approaches but still nothing. Please correct me.
Thanks!
... View more