mirror of
https://github.com/sasjs/core.git
synced 2025-12-10 22:14:35 +00:00
feat: adding mfv_existfile.sas and tests
This commit is contained in:
34
tests/viya/mfv_existfile.test.sas
Normal file
34
tests/viya/mfv_existfile.test.sas
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mfv_existfile macro function
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_uid.sas
|
||||
@li mfv_existfile.sas
|
||||
@li mp_assert.sas
|
||||
@li mv_createfile.sas
|
||||
|
||||
**/
|
||||
|
||||
options mprint sgen;
|
||||
|
||||
%let file=%mf_uid();
|
||||
|
||||
/* create a folder */
|
||||
filename somefile temp;
|
||||
data _null_;
|
||||
file somefile;
|
||||
put 'hello testings';
|
||||
run;
|
||||
%mv_createfile(path=&mcTestAppLoc/temp, name=&file..txt,inref=somefile)
|
||||
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(%mfv_existfile(&mcTestAppLoc/temp/&file..txt)=1),
|
||||
desc=Check if created file exists
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(%mfv_existfile(&mcTestAppLoc/temp/%mf_uid().txt)=0),
|
||||
desc=Check if non created file does not exist
|
||||
)
|
||||
48
viya/mfv_existfile.sas
Normal file
48
viya/mfv_existfile.sas
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
@file
|
||||
@brief Checks whether a file exists in SAS Drive
|
||||
@details Returns 1 if the file exists, and 0 if it doesn't. Works by
|
||||
attempting to assign a fileref with the filesrvc engine. If not found, the
|
||||
syscc is automatically set to a non zero value - so in this case it is reset.
|
||||
To avoid hiding issues, there is therefore a test at the start to ensure the
|
||||
syscc is zero.
|
||||
|
||||
Usage:
|
||||
|
||||
%put %mfv_existfile(/does/exist.txt);
|
||||
%put %mfv_existfile(/does/not/exist.txt);
|
||||
|
||||
@param filepath The full path to the file on SAS drive (eg /Public/myfile.txt)
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_abort.sas
|
||||
@li mf_getuniquefileref.sas
|
||||
|
||||
@version 3.5
|
||||
@author [Allan Bowe](https://www.linkedin.com/in/allanbowe/)
|
||||
**/
|
||||
|
||||
%macro mfv_existfile(filepath
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%mf_abort(
|
||||
iftrue=(&syscc ne 0),
|
||||
msg=Cannot enter mfv_existfile.sas with syscc=&syscc
|
||||
)
|
||||
|
||||
%local fref rc path name;
|
||||
%let fref=%mf_getuniquefileref();
|
||||
%let name=%scan(&filepath,-1,/);
|
||||
%let path=%substr(&filepath,1,%length(&filepath)-%length(&name)-1);
|
||||
|
||||
%if %sysfunc(filename(fref,,filesrvc,folderPath="&path" filename="&name"))=0
|
||||
%then %do;
|
||||
%sysfunc(fexist(&fref))
|
||||
%let rc=%sysfunc(filename(fref));
|
||||
%end;
|
||||
%else %do;
|
||||
0
|
||||
%let syscc=0;
|
||||
%end;
|
||||
|
||||
%mend mfv_existfile;
|
||||
Reference in New Issue
Block a user