Skip to content

Commit

Permalink
Merge pull request #195 from sasjs/issue194
Browse files Browse the repository at this point in the history
fix: supporting empty dirs in mp_dirlist. Test updated.
  • Loading branch information
allanbowe committed Mar 11, 2022
2 parents 1fdbc7c + 7e9e0fa commit 76207c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
16 changes: 9 additions & 7 deletions all.sas
Expand Up @@ -4214,19 +4214,20 @@ data &out_ds(compress=no
%end;
if rc = 0 then do;
did = dopen(fref);
if did=0 then do;
putlog "NOTE: This directory is empty, or does not exist - &path";
msg=sysmsg();
put msg;
put _all_;
stop;
end;
/* attribute is OS-dependent - could be "Directory" or "Directory Name" */
numopts=doptnum(did);
do i=1 to numopts;
foption=doptname(did,i);
if foption=:'Directory' then i=numopts;
end;
directory=dinfo(did,foption);
if did=0 then do;
putlog "NOTE: This directory is empty - " directory;
msg=sysmsg();
put _all_;
stop;
end;
rc = filename(fref);
end;
else do;
Expand Down Expand Up @@ -4362,7 +4363,8 @@ run;
proc sql;
drop table &out_ds;

%mend mp_dirlist;/**
%mend mp_dirlist;
/**
@file
@brief Creates a dataset containing distinct _formatted_ values
@details If no format is supplied, then the original value is used instead.
Expand Down
15 changes: 8 additions & 7 deletions base/mp_dirlist.sas
Expand Up @@ -94,19 +94,20 @@ data &out_ds(compress=no
%end;
if rc = 0 then do;
did = dopen(fref);
if did=0 then do;
putlog "NOTE: This directory is empty, or does not exist - &path";
msg=sysmsg();
put msg;
put _all_;
stop;
end;
/* attribute is OS-dependent - could be "Directory" or "Directory Name" */
numopts=doptnum(did);
do i=1 to numopts;
foption=doptname(did,i);
if foption=:'Directory' then i=numopts;
end;
directory=dinfo(did,foption);
if did=0 then do;
putlog "NOTE: This directory is empty - " directory;
msg=sysmsg();
put _all_;
stop;
end;
rc = filename(fref);
end;
else do;
Expand Down Expand Up @@ -242,4 +243,4 @@ run;
proc sql;
drop table &out_ds;

%mend mp_dirlist;
%mend mp_dirlist;
16 changes: 15 additions & 1 deletion tests/crossplatform/mp_dirlist.test.sas
Expand Up @@ -47,4 +47,18 @@ run;
iftrue=(%mf_nobs(work.mytable3)=2),
desc=Top level returned,
outds=work.test_results
)
)

%mp_dirlist(path=&root/b, outds=work.myTable4)
%mp_assert(
iftrue=(%mf_nobs(work.mytable4)=0),
desc=Empty table for empty directory,
outds=work.test_results
)

%mp_dirlist(path=&root/notexisting, outds=work.myTable5)
%mp_assert(
iftrue=(%mf_nobs(work.mytable5)=0),
desc=Empty table for non-existing directory,
outds=work.test_results
)

0 comments on commit 76207c4

Please sign in to comment.