| Walter Shafron
| |
|---|
| =========================================================================
| |
|---|
| Date: | Thu, 20 Feb 2003 07:41:51 -0800 |
| Reply-To: | Tom <tceyssens@AMADEUS.NET> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Tom <tceyssens@AMADEUS.NET> |
| Organization: | http://groups.google.com/ |
| Subject: | Using Windows KERNEL call: problem with creating directories... |
| Content-Type: | text/plain; charset=ISO-8859-1 |
Hi Everyone
Trying to create a directory structure and copy the files listed in
locations.txt into a corresponding storage directory on our S-drive.
Copying probably has a problem somewhere, but worked before:
S:\robot_backups\dated\<create Ddate>\<create Rrobot>\<create Stordir>
eg:
S:\robot_backups\dated\D01FEB2003\
S:\robot_backups\dated\D01FEB2003\R01\bin
S:\robot_backups\dated\D01FEB2003\R01\tab
S:\robot_backups\dated\D01FEB2003\R02\bin
S:\robot_backups\dated\D01FEB2003\R02\tab
Code you find at the end of this mail...
Unfortunately, my program doesnt get further than the first request in
the locations file (see end of mail), hence:
S:\robot_backups\dated\D01FEB2003\R01\bin
I've been breaking my head over why the Kernel call doesnt create
second level directories (r02, tab)... It just won't create more than
1 subdirectory to any given directory. Is there a solution to this
problem? (routine file appended below) I want to process about 100
files, and would really appreciate avoiding DOS pop-up/minimized
windows. I can't use Filename with PIPE, because it should all execute
with the datastep's iterations.
Perhaps you spot an obvious error in my code... Either way, any
solutions are much appreciated.
Thanks all
Tom Ceyssens
Amadeus Data Processing GmbH
Attached:
Program reads input files, merges, maps drives if not present, SHOULD
create directories if not present and copy files according to spec. *
means it will scan for all files in the given directory on the robot
(a robot being a windows pc).
the code:
filename sascbtbl 's:\Robot_backups\configuration\win32api.txt' ;
filename location 's:\Robot_backups\configuration\locations.txt'
lrecl=600 ;
filename networkc 's:\Robot_backups\configuration\common.txt'
lrecl=600 ;
filename myfile drivemap ;
data mymap;
informat ndrive $2. ;
length act $1 ;
retain act 'Y' ;
infile myfile end=eof ;
input ndrive $ ;
run;
data networkcn(keep=r robot ndrive) ;
infile networkc DSD DLM=',' truncover ;
length robot $2 ;
informat r 3. ndrive $2. ;
input r ndrive $ ;
if _N_ > 1 ;
robot=put(r,z2.) ;
ndrive = UPCASE(ndrive) ;
run ;
data fileloc(keep=r loc fn stordir) ;
infile location DSD DLM=',' truncover ;
informat r 3. loc fn stordir $50. ;
input r loc $ fn $ stordir $ ;
if _N_ > 1 ;
run ;
proc sort data=mymap ; by ndrive ; run ;
proc sort data=networkcn ; by ndrive ; run ;
data networkcn ;
merge networkcn(in=aa) mymap ;
by ndrive ;
if aa ;
run ;
proc sort data=networkcn ; by r ; run ;
proc sort data=fileloc ; by r stordir ; run ;
data job(drop=r) ;
merge fileloc(in=aa) networkcn ;
by r ;
if aa ;
run ;
options xwait xsync ;
data _null_ ;
retain destfld 'S:\Robot_backups\Dated\' runday ' ' ;
length from dest $100 ;
set job (obs=4) end=eof ;
by robot stordir ;
if _N_ = 1 then do ;
runday = 'D'!!put(date(),date9.) ;
dest = destfld!!runday ;
chk = dest ;
link checkdir ;
end ;
dest = destfld!!runday!!'\R'!!robot ;
if first.robot then do ;
put 'Processing robot ' robot ;
chk = dest ;
link checkdir ;
link mapdrive ;
end ;
if first.stordir then do ;
chk = trim(dest)!!'\'!!trim(stordir) ;
link checkdir ;
put 'Outputting to directory ' chk ;
end ;
if fn =: '*' then do ;
link scandir ;
end ;
else do ;
link docopy ;
end ;
if last.robot then do ;
put 'Finished processing robot ' robot ;
if act NE 'Y' then do ;
del = 'net use '!!ndrive!!' /delete' ;
Rc = ModuleN( "WinExec", del, 0) ;
end ;
end ;
return ;
checkdir:
rc = filename("bdir2",chk);
did = dopen("bdir2");
put 'Checking existence of ' chk ': ' did ' (> 0 = OK)' ;
if did = 0 then do ;
put 'Creating directory ' chk ;
chk = chk ;
rc = modulen('WinExec',chk,0) ;
pause = sleep(2) ;
end ;
else rc = dclose(did) ;
return ;
mapdrive:
put 'Checking if drive is mapped for robot ' robot ;
if act NE 'Y' then do ;
put 'Mapping drive for robot ' robot ;
use = 'net use '!!ndrive!!' \\robot-'!!robot!!'\c userpw
/USER:userid' ;
Rc = ModuleN( "WinExec", use, 0) ;
pause = sleep(1) ;
end ;
return ;
scandir:
scdir = trim(ndrive)!!'\'!!loc ;
put 'Scanning directory ' scdir ;
rc = filename("bdir3",scdir);
did = dopen("bdir3");
memcount=dnum(did);
do i=1 to memcount ;
fn = dread(did,i) ;
link docopy ;
output ;
end ;
rc = dclose(did) ;
return ;
docopy:
destfile = trim(dest)!!'\'!!trim(stordir)!!'\'!!trim(fn) ;
from = trim(ndrive)!!'\'!!trim(loc)!!fn ;
put 'Copying file ' from ' to ' destfile ;
rc = modulen('*e','CopyFileA',from,destfile,0) ;
return ;
run ;
filename sascbtbl clear;
***
the location.txt:
** Robotnr,directory\,filespec(* or complete filename),date_subdir
1,sentpath\tab\,*,tab
1,sentpath\bin\,node.cfg,bin
2,sentpath\tab\,*,tab
2,sentpath\bin\,node.cfg,bin
3,sentpath\tab\,*,tab
3,sentpath\bin\,node.cfg,bin
***
the common.txt:
*robotnr,mapdrive,*
1,k:,*
2,l:,*
3,m:,*
***
the routine win32api.txt:
ROUTINE CopyFileA
module=KERNEL32
minarg=3 maxarg=3 stackpop=called
returns=ushort;
arg 1 input char format=$cstr200.; * FROM ;
arg 2 input char format=$cstr200.; * TO ;
arg 3 input num format=pib4. byvalue;
* 1=Do Not Overwrite Existing
*;
* 0=Overwrite Existing File
*;
routine WinExec
minarg=2
maxarg=2
stackpop=called
module=KERNEL32
returns=short;
arg 1 char format=$cstr200.; * lpCmdLine command line statement;
arg 2 num format=pib2.; * nShowCmd application window
style;
*;
ROUTINE CreateDirectoryA
MINARG = 2
MAXARG = 2
STACKPOP = CALLED
MODULE = KERNEL32
RETURNS = SHORT;
ARG 1 CHAR FORMAT=$CSTR200. ;
ARG 2 NUM FORMAT=PIB4. ;
*;
|