65%macro mp_dirlist(path=%sysfunc(pathname(work))
67 , outds=work.mp_dirlist
73%let getattrs=%upcase(&getattrs)XX;
78%let out_ds=%str(&syslast);
81%
if &level=0 %then %
do;
82 %mp_dropmembers(%scan(&outds,-1,.), libref=WORK)
85data &out_ds(compress=no
86 keep=file_or_folder filepath filename ext msg directory level
88 length directory filepath $2000 fref fref2 $8 file_or_folder $6 filename $255
89 ext $20 msg $200 foption $16;
90 if _n_=1 then call missing(of _all_);
92 %
if &fref=0 %then %
do;
93 rc = filename(fref,
"&path");
102 putlog
"NOTE: This directory is empty, or does not exist - &path";
108 numopts=doptnum(did);
110 foption=doptname(did,i);
111 if foption=:
'Directory' then i=numopts;
113 directory=dinfo(did,foption);
123 filename = dread(did, i);
124 filepath=cats(directory,
'/',filename);
125 rc = filename(fref2,filepath);
128 if did > 0 then file_or_folder=
'folder';
132 if midf > 0 then file_or_folder=
'file';
135 if index(fmsg,
'File is in use') or index(dmsg,'is not a directory')
136 then file_or_folder='file';
137 else if index(fmsg,'Insufficient authorization') then file_or_folder='file';
138 else if file_or_folder='' then file_or_folder='locked';
140 if file_or_folder='file' then do;
141 ext = prxchange('s/.*\.{1,1}(.*)/$1/
', 1, filename);
142 if filename = ext then ext = ' ';
146 file_or_folder='folder
';
151 %if &showparent=YES and &level=0 %then %do;
153 file_or_folder='folder
';
155 filename=scan(directory,-1,'/\
');
163%if %substr(&getattrs,1,1)=Y %then %do;
166 length infoname infoval $60 fref $8;
167 if _n_=1 then call missing(fref);
168 rc=filename(fref,filepath);
169 drop rc infoname fid i close fref;
170 if file_or_folder='file
' then do;
174 putlog "Could not open file:" filepath fid= ;
175 sasname='_MCNOTVALID_
';
178 else do i=1 to foptnum(fid);
179 infoname=foptname(fid,i);
180 infoval=finfo(fid,infoname);
181 sasname=compress(infoname, '_
', 'adik
');
182 if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
183 if upcase(sasname) ne 'FILENAME
' then output;
191 putlog "Could not open folder:" filepath fid= ;
192 sasname='_MCNOTVALID_
';
195 else do i=1 to doptnum(fid);
196 infoname=doptname(fid,i);
197 infoval=dinfo(fid,infoname);
198 sasname=compress(infoname, '_
', 'adik
');
199 if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
200 if upcase(sasname) ne 'FILENAME
' then output;
207 proc transpose data=&out_ds out=&out_ds(drop=_:);
210 by filepath file_or_folder filename ext ;
215 set &out_ds(where=(filepath ne ''));
222%if %mf_existds(&outds) %then %do;
223 %local basevars appvars newvars;
224 %let basevars=%mf_getvarlist(&outds);
225 %let appvars=%mf_getvarlist(&out_ds);
226 %let newvars=%length(%mf_wordsinstr1butnotstr2(Str1=&appvars,Str2=&basevars));
227 %if &newvars>0 %then %do;
233 proc append base=&outds data=&out_ds force nowarn;
238 proc append base=&outds data=&out_ds;
243%if &maxdepth>&level or &maxdepth=MAX %then %do;
246 where file_or_folder='folder
';
247 %if &showparent=YES and &level=0 %then %do;
248 if filepath ne directory;
251 code=cats('%nrstr(%mp_dirlist(path=
',filepath,",outds=&outds"
252 ,",getattrs=&getattrs,level=%eval(&level+1),maxdepth=&maxdepth))");