SASUnit Examples  Version 1.5.0
windows/_copydir.sas
Go to the documentation of this file.
1 
24 %macro _copyDir (i_from
25  ,i_to
26  );
27 
28  %LOCAL l_i_from l_i_to logfile;
29 
30  /* save and modify os command options */
31  %local xwait xsync xmin;
32  %let xwait=%sysfunc(getoption(xwait));
33  %let xsync=%sysfunc(getoption(xsync));
34  %let xmin =%sysfunc(getoption(xmin));
35  options noxwait xsync xmin;
36 
37  %let i_from = %qsysfunc(translate(&i_from,\,/));
38  %let i_to = %qsysfunc(translate(&i_to ,\,/));
39  %let logfile=%sysfunc(pathname(work))\___log.txt;
40 
41  /*-- XCOPY
42  /E copy directories (even empty ones) and files recursively
43  /I do not prompt before file or directory creation
44  /Y do not prompt before overwriting target
45  --*/
46  %sysexec (xcopy "&i_from" "&i_to" /E /I /Y > "&logfile" 2>&1);
47 
48  %if &g_verbose. %then %do;
49  %put ======== OS Command Start ========;
50  /* Evaluate sysexec´s return code*/
51  %if &sysrc. = 0 %then %put &g_note.(SASUNIT): Sysrc : 0 -> SYSEXEC SUCCESSFUL;
52  %else %put &g_error.(SASUNIT): Sysrc : &sysrc -> An Error occured;
53 
54  /* put sysexec command to log*/
55  %put &g_note.(SASUNIT): SYSEXEC COMMAND IS: xcopy "&i_from" "&i_to" /E /I /Y > "&logfile";
56 
57  /* write &logfile to the log*/
58  data _null_;
59  infile "&logfile" truncover lrecl=512;
60  input line $512.;
61  putlog line;
62  run;
63  %put ======== OS Command End ========;
64  %end;
65 
66  options &xwait &xsync &xmin;
67 
68 %mend _copyDir;