mirror of
https://github.com/sasjs/core.git
synced 2026-01-15 12:30:06 +00:00
feat: adding fileref support for mp_dirlist, as well as a directory column on the output dataset
This commit is contained in:
33
all.sas
33
all.sas
@@ -380,7 +380,7 @@ options noquotelenmax;
|
|||||||
@brief Returns the engine type of a SAS library
|
@brief Returns the engine type of a SAS library
|
||||||
@details Usage:
|
@details Usage:
|
||||||
|
|
||||||
%put %mf_getEngine(SASHELP);
|
%put %mf_getengine(SASHELP);
|
||||||
|
|
||||||
returns:
|
returns:
|
||||||
> V9
|
> V9
|
||||||
@@ -398,9 +398,10 @@ options noquotelenmax;
|
|||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
**/
|
|
||||||
|
|
||||||
%macro mf_getEngine(libref
|
**/ /** \cond */
|
||||||
|
|
||||||
|
%macro mf_getengine(libref
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%local dsid engnum rc engine;
|
%local dsid engnum rc engine;
|
||||||
|
|
||||||
@@ -419,7 +420,8 @@ options noquotelenmax;
|
|||||||
&engine
|
&engine
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
/**
|
|
||||||
|
/** \endcond *//**
|
||||||
@file
|
@file
|
||||||
@brief Returns the size of a file in bytes.
|
@brief Returns the size of a file in bytes.
|
||||||
@details Provide full path/filename.extension to the file, eg:
|
@details Provide full path/filename.extension to the file, eg:
|
||||||
@@ -1974,6 +1976,8 @@ run;
|
|||||||
|
|
||||||
%mp_dirlist(outds=cwdfileprops, getattrs=YES)
|
%mp_dirlist(outds=cwdfileprops, getattrs=YES)
|
||||||
|
|
||||||
|
%mp_dirlist(fref=MYFREF)
|
||||||
|
|
||||||
@warning In a Unix environment, the existence of a named pipe will cause this
|
@warning In a Unix environment, the existence of a named pipe will cause this
|
||||||
macro to hang. Therefore this tool should be used with caution in a SAS 9 web
|
macro to hang. Therefore this tool should be used with caution in a SAS 9 web
|
||||||
application, as it can use up all available multibridge sessions if requests
|
application, as it can use up all available multibridge sessions if requests
|
||||||
@@ -1983,12 +1987,14 @@ run;
|
|||||||
|
|
||||||
|
|
||||||
@param path= for which to return contents
|
@param path= for which to return contents
|
||||||
|
@param fref= Provide a DISK engine fileref as an alternative to PATH
|
||||||
@param outds= the output dataset to create
|
@param outds= the output dataset to create
|
||||||
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
|
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
|
||||||
all attributes for each file / folder.
|
all attributes for each file / folder.
|
||||||
|
|
||||||
|
|
||||||
@returns outds contains the following variables:
|
@returns outds contains the following variables:
|
||||||
|
- directory (containing folder)
|
||||||
- file_or_folder (file / folder)
|
- file_or_folder (file / folder)
|
||||||
- filepath (path/to/file.name)
|
- filepath (path/to/file.name)
|
||||||
- filename (just the file name)
|
- filename (just the file name)
|
||||||
@@ -2001,18 +2007,26 @@ run;
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_dirlist(path=%sysfunc(pathname(work))
|
%macro mp_dirlist(path=%sysfunc(pathname(work))
|
||||||
|
, fref=0
|
||||||
, outds=work.mp_dirlist
|
, outds=work.mp_dirlist
|
||||||
, getattrs=NO
|
, getattrs=NO
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%let getattrs=%upcase(&getattrs)XX;
|
%let getattrs=%upcase(&getattrs)XX;
|
||||||
|
|
||||||
data &outds (compress=no keep=file_or_folder filepath filename ext msg);
|
data &outds (compress=no keep=file_or_folder filepath filename ext msg directory);
|
||||||
length filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
|
length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
|
||||||
rc = filename(fref, "&path");
|
%if &fref=0 %then %do;
|
||||||
|
rc = filename(fref, "&path");
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
fref="&fref";
|
||||||
|
rc=0;
|
||||||
|
%end;
|
||||||
if rc = 0 then do;
|
if rc = 0 then do;
|
||||||
did = dopen(fref);
|
did = dopen(fref);
|
||||||
|
directory=dinfo(did,'Directory');
|
||||||
if did=0 then do;
|
if did=0 then do;
|
||||||
putlog "NOTE: This directory is empty - &path";
|
putlog "NOTE: This directory is empty - " directory;
|
||||||
msg=sysmsg();
|
msg=sysmsg();
|
||||||
put _all_;
|
put _all_;
|
||||||
stop;
|
stop;
|
||||||
@@ -2027,7 +2041,7 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
|
|||||||
dnum = dnum(did);
|
dnum = dnum(did);
|
||||||
do i = 1 to dnum;
|
do i = 1 to dnum;
|
||||||
filename = dread(did, i);
|
filename = dread(did, i);
|
||||||
rc = filename(fref2, "&path/"!!filename);
|
rc = filename(fref2, cats(directory,'/',filename));
|
||||||
midd=dopen(fref2);
|
midd=dopen(fref2);
|
||||||
dmsg=sysmsg();
|
dmsg=sysmsg();
|
||||||
if did > 0 then file_or_folder='folder';
|
if did > 0 then file_or_folder='folder';
|
||||||
@@ -2527,7 +2541,6 @@ create table &outds as
|
|||||||
datetime2 format or regular decimal type
|
datetime2 format or regular decimal type
|
||||||
@version 9.3
|
@version 9.3
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@source https://github.com/sasjs/core
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
|
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
%mp_dirlist(outds=cwdfileprops, getattrs=YES)
|
%mp_dirlist(outds=cwdfileprops, getattrs=YES)
|
||||||
|
|
||||||
|
%mp_dirlist(fref=MYFREF)
|
||||||
|
|
||||||
@warning In a Unix environment, the existence of a named pipe will cause this
|
@warning In a Unix environment, the existence of a named pipe will cause this
|
||||||
macro to hang. Therefore this tool should be used with caution in a SAS 9 web
|
macro to hang. Therefore this tool should be used with caution in a SAS 9 web
|
||||||
application, as it can use up all available multibridge sessions if requests
|
application, as it can use up all available multibridge sessions if requests
|
||||||
@@ -29,12 +31,14 @@
|
|||||||
|
|
||||||
|
|
||||||
@param path= for which to return contents
|
@param path= for which to return contents
|
||||||
|
@param fref= Provide a DISK engine fileref as an alternative to PATH
|
||||||
@param outds= the output dataset to create
|
@param outds= the output dataset to create
|
||||||
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
|
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
|
||||||
all attributes for each file / folder.
|
all attributes for each file / folder.
|
||||||
|
|
||||||
|
|
||||||
@returns outds contains the following variables:
|
@returns outds contains the following variables:
|
||||||
|
- directory (containing folder)
|
||||||
- file_or_folder (file / folder)
|
- file_or_folder (file / folder)
|
||||||
- filepath (path/to/file.name)
|
- filepath (path/to/file.name)
|
||||||
- filename (just the file name)
|
- filename (just the file name)
|
||||||
@@ -47,18 +51,26 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_dirlist(path=%sysfunc(pathname(work))
|
%macro mp_dirlist(path=%sysfunc(pathname(work))
|
||||||
|
, fref=0
|
||||||
, outds=work.mp_dirlist
|
, outds=work.mp_dirlist
|
||||||
, getattrs=NO
|
, getattrs=NO
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%let getattrs=%upcase(&getattrs)XX;
|
%let getattrs=%upcase(&getattrs)XX;
|
||||||
|
|
||||||
data &outds (compress=no keep=file_or_folder filepath filename ext msg);
|
data &outds (compress=no keep=file_or_folder filepath filename ext msg directory);
|
||||||
length filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
|
length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
|
||||||
rc = filename(fref, "&path");
|
%if &fref=0 %then %do;
|
||||||
|
rc = filename(fref, "&path");
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
fref="&fref";
|
||||||
|
rc=0;
|
||||||
|
%end;
|
||||||
if rc = 0 then do;
|
if rc = 0 then do;
|
||||||
did = dopen(fref);
|
did = dopen(fref);
|
||||||
|
directory=dinfo(did,'Directory');
|
||||||
if did=0 then do;
|
if did=0 then do;
|
||||||
putlog "NOTE: This directory is empty - &path";
|
putlog "NOTE: This directory is empty - " directory;
|
||||||
msg=sysmsg();
|
msg=sysmsg();
|
||||||
put _all_;
|
put _all_;
|
||||||
stop;
|
stop;
|
||||||
@@ -73,7 +85,7 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
|
|||||||
dnum = dnum(did);
|
dnum = dnum(did);
|
||||||
do i = 1 to dnum;
|
do i = 1 to dnum;
|
||||||
filename = dread(did, i);
|
filename = dread(did, i);
|
||||||
rc = filename(fref2, "&path/"!!filename);
|
rc = filename(fref2, cats(directory,'/',filename));
|
||||||
midd=dopen(fref2);
|
midd=dopen(fref2);
|
||||||
dmsg=sysmsg();
|
dmsg=sysmsg();
|
||||||
if did > 0 then file_or_folder='folder';
|
if did > 0 then file_or_folder='folder';
|
||||||
|
|||||||
Reference in New Issue
Block a user