From 18bc6c889db1518671f3f19c98dd18ec4dabcd72 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 26 May 2021 23:37:06 +0300 Subject: [PATCH] feat: adding mfv_existfolder.sas and tests --- tests/viya/mfv_existfolder.test.sas | 29 +++++++++++++++++++ viya/mfv_existfolder.sas | 45 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/viya/mfv_existfolder.test.sas create mode 100644 viya/mfv_existfolder.sas diff --git a/tests/viya/mfv_existfolder.test.sas b/tests/viya/mfv_existfolder.test.sas new file mode 100644 index 0000000..a676d86 --- /dev/null +++ b/tests/viya/mfv_existfolder.test.sas @@ -0,0 +1,29 @@ +/** + @file + @brief Testing mfv_existfolder macro function + +

SAS Macros

+ @li mf_uid.sas + @li mfv_existfolder.sas + @li mp_assert.sas + @li mv_createfolder.sas + +**/ + +options mprint sgen; + +%let folder=%mf_uid(); + +/* create a folder */ +%mv_createfolder(path=&mcTestAppLoc/temp/&folder) + + +%mp_assert( + iftrue=(%mfv_existfolder(&mcTestAppLoc/temp/&folder)=1), + desc=Check if created folder exists +) + +%mp_assert( + iftrue=(%mfv_existfolder(&mcTestAppLoc/temp/&folder/%mf_uid()/noway)=0), + desc=Check if non created folder does not exist +) \ No newline at end of file diff --git a/viya/mfv_existfolder.sas b/viya/mfv_existfolder.sas new file mode 100644 index 0000000..cdd3e9a --- /dev/null +++ b/viya/mfv_existfolder.sas @@ -0,0 +1,45 @@ +/** + @file + @brief Checks whether a folder exists in SAS Drive + @details Returns 1 if the folder 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_existfolder(/does/exist); + %put %mfv_existfolder(/does/not/exist); + + @param path The path to the folder on SAS drive + +

SAS Macros

+ @li mf_abort.sas + @li mf_getuniquefileref.sas + + @version 3.5 + @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/) +**/ + +%macro mfv_existfolder(path +)/*/STORE SOURCE*/; + + %mf_abort( + iftrue=(&syscc ne 0), + msg=Cannot enter mfv_existfolder.sas with syscc=&syscc + ) + + %local fref rc; + %let fref=%mf_getuniquefileref(); + + %if %sysfunc(filename(fref,,filesrvc,folderPath="&path"))=0 %then %do; + 1 + %let rc=%sysfunc(filename(fref)); + %end; + %else %do; + 0 + %let syscc=0; + %end; + +%mend mfv_existfolder; \ No newline at end of file