I'm trying to get a list of files in a directory and the subdirectories with file attributes, in particular the size of each file.
the files are listed in the main directory, but there a bunch of subdirectories with files. I've been using the following code, but
have not figured out how to get the size of the file, it only gives the directory and file. I've used the FINFO function, but doesn't give the size.
%macro list_files(dir,ext); %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 %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;*/ %if %qscan(&name,2,.) ne %then %do; %put &dir/&name;
data _tmp; length dir $512 name $100; dir=symget("dir"); name=symget("name");
size=FINFO(OPEN(symget("name")), 'FILE SIZE (BYTES)'); run;
proc append base=want
data =_tmp; run;quit;
%end;
%else %if %qscan(&name,2,.) = %then %do; %list_files(&dir/&name,&ext) %end;
%end;
%let rc=%sysfunc(dclose(&did)); %let rc=%sysfunc(filename(filrf));
%mend list_files; %list_files(/gpfsFS2/sasdata/adhoc/pofin/nps/npsts/prod/cera/data,*)
... View more