@sasjs/core 2.52.0 → 2.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mp_copyfolder.sas +78 -0
- package/base/mp_dirlist.sas +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief A macro to recursively copy a directory
|
|
4
|
+
@details Performs a recursive directory listing then works from top to bottom
|
|
5
|
+
copying files and creating subdirectories.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
|
|
9
|
+
%let rootdir=%sysfunc(pathname(work))/demo;
|
|
10
|
+
%let copydir=%sysfunc(pathname(work))/demo_copy;
|
|
11
|
+
%mf_mkdir(&rootdir)
|
|
12
|
+
%mf_mkdir(&rootdir/subdir)
|
|
13
|
+
%mf_mkdir(&rootdir/subdir/subsubdir)
|
|
14
|
+
data "&rootdir/subdir/example.sas7bdat";
|
|
15
|
+
run;
|
|
16
|
+
|
|
17
|
+
%mp_copyfolder(&rootdir,©dir)
|
|
18
|
+
|
|
19
|
+
@param source Unquoted path to the folder to copy from.
|
|
20
|
+
@param target Unquoted path to the folder to copy to.
|
|
21
|
+
|
|
22
|
+
<h4> SAS Macros </h4>
|
|
23
|
+
@li mf_getuniquename.sas
|
|
24
|
+
@li mf_isdir.sas
|
|
25
|
+
@li mf_mkdir.sas
|
|
26
|
+
@li mp_abort.sas
|
|
27
|
+
@li mp_dirlist.sas
|
|
28
|
+
|
|
29
|
+
<h4> Related Macros </h4>
|
|
30
|
+
@li mp_copyfolder.test.sas
|
|
31
|
+
|
|
32
|
+
**/
|
|
33
|
+
|
|
34
|
+
%macro mp_copyfolder(source,target);
|
|
35
|
+
|
|
36
|
+
%mp_abort(iftrue=(%mf_isdir(&source)=0)
|
|
37
|
+
,mac=&sysmacroname
|
|
38
|
+
,msg=%str(Source dir does not exist (&source))
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
%mf_mkdir(&target)
|
|
42
|
+
|
|
43
|
+
%mp_abort(iftrue=(%mf_isdir(&target)=0)
|
|
44
|
+
,mac=&sysmacroname
|
|
45
|
+
,msg=%str(Target dir could not be created (&target))
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
/* prep temp table */
|
|
49
|
+
%local tempds;
|
|
50
|
+
%let tempds=%mf_getuniquename();
|
|
51
|
+
|
|
52
|
+
/* recursive directory listing */
|
|
53
|
+
%mp_dirlist(path=&source,outds=work.&tempds, maxdepth=MAX)
|
|
54
|
+
|
|
55
|
+
/* create folders and copy content */
|
|
56
|
+
data _null_;
|
|
57
|
+
set work.&tempds;
|
|
58
|
+
filepath2="&target/"!!substr(filepath,%length(&source)+2);
|
|
59
|
+
if file_or_folder='folder' then call execute('%mf_mkdir('!!filepath2!!')');
|
|
60
|
+
else do;
|
|
61
|
+
length fref1 fref2 $8;
|
|
62
|
+
rc1=filename(fref1,filepath,'disk','recfm=n');
|
|
63
|
+
rc2=filename(fref2,filepath2,'disk','recfm=n');
|
|
64
|
+
if fcopy(fref1,fref2) ne 0 then do;
|
|
65
|
+
sysmsg=sysmsg();
|
|
66
|
+
putlog "%str(ERR)OR: Unable to copy " filepath " to " filepath2;
|
|
67
|
+
putlog sysmg=;
|
|
68
|
+
end;
|
|
69
|
+
end;
|
|
70
|
+
rc=filename(fref1);
|
|
71
|
+
rc=filename(fref2);
|
|
72
|
+
run;
|
|
73
|
+
|
|
74
|
+
/* tidy up */
|
|
75
|
+
proc sql;
|
|
76
|
+
drop table work.&tempds;
|
|
77
|
+
|
|
78
|
+
%mend mp_copyfolder;
|
package/base/mp_dirlist.sas
CHANGED
package/package.json
CHANGED