mirror of
https://github.com/sasjs/core.git
synced 2026-01-15 20:40:05 +00:00
feat(*): recreate library as scoped package
This commit is contained in:
67
base/mf_mkdir.sas
Executable file
67
base/mf_mkdir.sas
Executable file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
@file
|
||||
@brief Creates a directory, including any intermediate directories
|
||||
@details Works on windows and unix environments via dcreate function.
|
||||
Usage:
|
||||
|
||||
%mf_mkdir(/some/path/name)
|
||||
|
||||
|
||||
@param dir relative or absolute pathname. Unquoted.
|
||||
@version 9.2
|
||||
|
||||
**/
|
||||
|
||||
%macro mf_mkdir(dir
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local lastchar child parent;
|
||||
|
||||
%let lastchar = %substr(&dir, %length(&dir));
|
||||
%if (%bquote(&lastchar) eq %str(:)) %then %do;
|
||||
/* Cannot create drive mappings */
|
||||
%return;
|
||||
%end;
|
||||
|
||||
%if (%bquote(&lastchar)=%str(/)) or (%bquote(&lastchar)=%str(\)) %then %do;
|
||||
/* last char is a slash */
|
||||
%if (%length(&dir) eq 1) %then %do;
|
||||
/* one single slash - root location is assumed to exist */
|
||||
%return;
|
||||
%end;
|
||||
%else %do;
|
||||
/* strip last slash */
|
||||
%let dir = %substr(&dir, 1, %length(&dir)-1);
|
||||
%end;
|
||||
%end;
|
||||
|
||||
%if (%sysfunc(fileexist(%bquote(&dir))) = 0) %then %do;
|
||||
/* directory does not exist so prepare to create */
|
||||
/* first get the childmost directory */
|
||||
%let child = %scan(&dir, -1, %str(/\:));
|
||||
|
||||
/*
|
||||
If child name = path name then there are no parents to create. Else
|
||||
they must be recursively scanned.
|
||||
*/
|
||||
|
||||
%if (%length(&dir) gt %length(&child)) %then %do;
|
||||
%let parent = %substr(&dir, 1, %length(&dir)-%length(&child));
|
||||
%mf_mkdir(&parent)
|
||||
%end;
|
||||
|
||||
/*
|
||||
Now create the directory. Complain loudly of any errors.
|
||||
*/
|
||||
|
||||
%let dname = %sysfunc(dcreate(&child, &parent));
|
||||
%if (%bquote(&dname) eq ) %then %do;
|
||||
%put %str(ERR)OR: could not create &parent + &child;
|
||||
%abort cancel;
|
||||
%end;
|
||||
%else %do;
|
||||
%put Directory created: &dir;
|
||||
%end;
|
||||
%end;
|
||||
/* exit quietly if directory did exist.*/
|
||||
%mend;
|
||||
Reference in New Issue
Block a user