mirror of
https://github.com/sasjs/core.git
synced 2025-12-10 14:04:36 +00:00
Merge pull request #196 from sasjs/delfile
feat: adding new mf_deletefile macro (and test)
This commit is contained in:
49
all.sas
49
all.sas
@@ -95,6 +95,37 @@ options noquotelenmax;
|
||||
%mend mf_dedup;
|
||||
|
||||
|
||||
/**
|
||||
@file
|
||||
@brief Deletes a physical file, if it exists
|
||||
@details Usage:
|
||||
|
||||
%mf_writefile(&sasjswork/myfile.txt,l1=some content)
|
||||
|
||||
%mf_deletefile(&sasjswork/myfile.txt)
|
||||
|
||||
%mf_deletefile(&sasjswork/myfile.txt)
|
||||
|
||||
|
||||
@param filepath Full path to the target file
|
||||
|
||||
@returns The return code from the fdelete() invocation
|
||||
|
||||
<h4> Related Macros </h4>
|
||||
@li mf_deletefile.test.sas
|
||||
@li mf_writefile.sas
|
||||
|
||||
@version 9.2
|
||||
@author Allan Bowe
|
||||
**/
|
||||
|
||||
%macro mf_deletefile(file
|
||||
)/*/STORE SOURCE*/;
|
||||
%local rc fref;
|
||||
%let rc= %sysfunc(filename(fref,&file));
|
||||
%if %sysfunc(fdelete(&fref)) ne 0 %then %put %sysfunc(sysmsg());
|
||||
%let rc= %sysfunc(filename(fref));
|
||||
%mend mf_deletefile;
|
||||
/**
|
||||
@file mf_existds.sas
|
||||
@brief Checks whether a dataset OR a view exists.
|
||||
@@ -17781,7 +17812,7 @@ filename __shake clear;
|
||||
%let platform_object_path=%mf_loc(POF);
|
||||
%let ds=%mf_getuniquename(prefix=spkexportable);
|
||||
|
||||
%mm_tree(root=%str(&metaloc) ,types=EXPORTABLE ,outds=&ds)
|
||||
%mm_tree(root=%str(&metaloc),types=EXPORTABLE ,outds=&ds)
|
||||
|
||||
%if %mf_isblank(&outref)=1 %then %let outref=%mf_getuniquefileref();
|
||||
|
||||
@@ -17790,19 +17821,27 @@ data _null_;
|
||||
file &outref lrecl=32767;
|
||||
length str $32767;
|
||||
if _n_=1 then do;
|
||||
put "# Script generated by &sysuserid on %sysfunc(datetime(),datetime19.)";
|
||||
put "cd ""&platform_object_path"" \";
|
||||
put "; ./ExportPackage -host &host -port &port -user &mmxuser \";
|
||||
put " -disableX11 -password &mmxpass \"
|
||||
put " -disableX11 -password &mmxpass \";
|
||||
put " -package ""&cmdoutloc/&cmdoutname..spk"" \";
|
||||
end;
|
||||
/* exclude particular patterns from the exported SPK */
|
||||
%if "&excludevars" ne "0" %then %do;
|
||||
/* ignore top level folder else all subcontent will be exported regardless */
|
||||
if _n_>1;
|
||||
%do i=1 %to %sysfunc(countw(&excludevars));
|
||||
%let var=%scan(&excludevars,&i);
|
||||
if index(path,symget("&var")) ne 0;
|
||||
if _n_=1 then do;
|
||||
length excludestr&i $1000;
|
||||
retain excludestr&i;
|
||||
excludestr&i=symget("&var");
|
||||
putlog excludestr&i=;
|
||||
putlog path=;
|
||||
end;
|
||||
if index(path,cats(excludestr&i))=0 and index(name,cats(excludestr&i))=0;
|
||||
%end;
|
||||
/* ignore top level folder else all subcontent will be exported regardless */
|
||||
if _n_>1;
|
||||
%end;
|
||||
str=' -objects '!!cats('"',path,'/',name,"(",publictype,')" \');
|
||||
put str;
|
||||
|
||||
31
base/mf_deletefile.sas
Normal file
31
base/mf_deletefile.sas
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
@file
|
||||
@brief Deletes a physical file, if it exists
|
||||
@details Usage:
|
||||
|
||||
%mf_writefile(&sasjswork/myfile.txt,l1=some content)
|
||||
|
||||
%mf_deletefile(&sasjswork/myfile.txt)
|
||||
|
||||
%mf_deletefile(&sasjswork/myfile.txt)
|
||||
|
||||
|
||||
@param filepath Full path to the target file
|
||||
|
||||
@returns The return code from the fdelete() invocation
|
||||
|
||||
<h4> Related Macros </h4>
|
||||
@li mf_deletefile.test.sas
|
||||
@li mf_writefile.sas
|
||||
|
||||
@version 9.2
|
||||
@author Allan Bowe
|
||||
**/
|
||||
|
||||
%macro mf_deletefile(file
|
||||
)/*/STORE SOURCE*/;
|
||||
%local rc fref;
|
||||
%let rc= %sysfunc(filename(fref,&file));
|
||||
%if %sysfunc(fdelete(&fref)) ne 0 %then %put %sysfunc(sysmsg());
|
||||
%let rc= %sysfunc(filename(fref));
|
||||
%mend mf_deletefile;
|
||||
@@ -102,7 +102,7 @@
|
||||
%let platform_object_path=%mf_loc(POF);
|
||||
%let ds=%mf_getuniquename(prefix=spkexportable);
|
||||
|
||||
%mm_tree(root=%str(&metaloc) ,types=EXPORTABLE ,outds=&ds)
|
||||
%mm_tree(root=%str(&metaloc),types=EXPORTABLE ,outds=&ds)
|
||||
|
||||
%if %mf_isblank(&outref)=1 %then %let outref=%mf_getuniquefileref();
|
||||
|
||||
@@ -111,19 +111,27 @@ data _null_;
|
||||
file &outref lrecl=32767;
|
||||
length str $32767;
|
||||
if _n_=1 then do;
|
||||
put "# Script generated by &sysuserid on %sysfunc(datetime(),datetime19.)";
|
||||
put "cd ""&platform_object_path"" \";
|
||||
put "; ./ExportPackage -host &host -port &port -user &mmxuser \";
|
||||
put " -disableX11 -password &mmxpass \"
|
||||
put " -disableX11 -password &mmxpass \";
|
||||
put " -package ""&cmdoutloc/&cmdoutname..spk"" \";
|
||||
end;
|
||||
/* exclude particular patterns from the exported SPK */
|
||||
%if "&excludevars" ne "0" %then %do;
|
||||
/* ignore top level folder else all subcontent will be exported regardless */
|
||||
if _n_>1;
|
||||
%do i=1 %to %sysfunc(countw(&excludevars));
|
||||
%let var=%scan(&excludevars,&i);
|
||||
if index(path,symget("&var")) ne 0;
|
||||
if _n_=1 then do;
|
||||
length excludestr&i $1000;
|
||||
retain excludestr&i;
|
||||
excludestr&i=symget("&var");
|
||||
putlog excludestr&i=;
|
||||
putlog path=;
|
||||
end;
|
||||
if index(path,cats(excludestr&i))=0 and index(name,cats(excludestr&i))=0;
|
||||
%end;
|
||||
/* ignore top level folder else all subcontent will be exported regardless */
|
||||
if _n_>1;
|
||||
%end;
|
||||
str=' -objects '!!cats('"',path,'/',name,"(",publictype,')" \');
|
||||
put str;
|
||||
|
||||
29
tests/crossplatform/mf_deletefile.test.sas
Normal file
29
tests/crossplatform/mf_deletefile.test.sas
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mf_deletefile.sas macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_deletefile.sas
|
||||
@li mf_writefile.sas
|
||||
@li mp_assert.sas
|
||||
@li mp_assertscope.sas
|
||||
|
||||
**/
|
||||
|
||||
%let test1file=&sasjswork/myfile1.txt;
|
||||
|
||||
%mf_writefile(&test1file,l1=some content)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(%sysfunc(fileexist(&test1file))=1),
|
||||
desc=Check &test1file exists
|
||||
)
|
||||
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%mf_deletefile(&test1file)
|
||||
%mp_assertscope(COMPARE)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(%sysfunc(fileexist(&test1file))=0),
|
||||
desc=Check &test1file no longer exists
|
||||
)
|
||||
Reference in New Issue
Block a user