CORE
mp_dirlist.sas
Go to the documentation of this file.
1 
27 %macro mp_dirlist(path=%sysfunc(pathname(work))
28  , outds=work.mp_dirlist
29  );
30 
31 data &outds (compress=no keep=file_or_folder filepath filename ext msg);
32  length filepath $500 fref $8 file_or_folder $6 filename $80 ext $20 msg $200;
33  rc = filename(fref, "&path");
34  if rc = 0 then do;
35  did = dopen(fref);
36  if did=0 then do;
37  putlog "NOTE: This directory is empty - &path";
38  msg=sysmsg();
39  put _all_;
40  stop;
41  end;
42  rc = filename(fref);
43  end;
44  else do;
45  msg=sysmsg();
46  put _all_;
47  stop;
48  end;
49  dnum = dnum(did);
50  do i = 1 to dnum;
51  filename = dread(did, i);
52  fid = mopen(did, filename);
53  if fid > 0 then do;
54  file_or_folder='file ';
55  ext = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename);
56  if filename = ext then ext = ' ';
57  end;
58  else do;
59  ext='';
60  file_or_folder='folder';
61  end;
62  filepath="&path/"!!filename;
63  output;
64  end;
65  rc = dclose(did);
66  stop;
67 run;
68 
69 %mend;