home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
UPDIR.CMD
< prev
Wrap
OS/2 REXX Batch file
|
1993-02-05
|
4KB
|
145 lines
/*****************************************************************************/
/* */
/* UPDIR: update a target directory from a given source directory. All */
/* files in the target directory are compared to files of the same name */
/* in the source directory. If they are older, they are replaced by the */
/* newer file from the source directory. No other changes are made. */
/* */
/* Requires Personal REXX or REXXLIB (dosdrive, doscd, dosdir, dosdirpos, */
/* dosisdir, parsefn, upper functions). */
/* */
/* Command format: UPDIR <target> <source> */
/* */
/*****************************************************************************/
parse arg dir1 dir2 .
if dir1 = '' then do
say 'Disk or directory not specified.'
exit 1
end
if dir2 = '' then
dir2 = dosdrive()':'doscd()
if right(dir2, 1) = ':' then
dir2 = dir2||doscd(dir2)
if \dosisdir(dir2) then do
say dir2 'not found.'
exit 2
end
parse value parsedname(dir1) with drive ',' path ',' fileid
parse value parsedname(dir2) with drive2 ',' path2 ',' fileid2
dir1 = drive':'path
dir2 = drive2':'path2
fullid = dir1||fileid
parse upper value fullid dir1 dir2 with fullid dir1 dir2
file = dosdir(fullid)
if file = '' then do
say 'Files "'fullid'" not found.'
exit 2
end
newi = 0
neweri = 0
olderi = 0
samei = 0
say 'Updating' dir1 'from' dir2 '...'
do while file \= ''
position = dosdirpos()
parse var file fname . fdate ftime .
newfile = dosdir(dir2||fname)
parse var newfile newfname . newfdate newftime .
comp = compdate(fdate ftime,newfdate newftime)
select
when newfile = '' then do
newi = newi + 1
new.newi = fname
end
when comp < 0 then do
olderi = olderi + 1
older.olderi = fname
end
when comp > 0 then do
neweri = neweri + 1
newer.neweri = fname
end
otherwise do
samei = samei + 1
same.samei = fname
end
end
file = dosdir(,,,,position)
end
sp = ' '
if olderi > 0 then do
say 'The following files are older on' dir1 'than on' dir2
say 'The older version will be updated.'
call replace older, olderi
end
if neweri > 0 then do
say 'The following files are newer on' dir1 'than on' dir2
call show newer, neweri
end
if newi > 0 then do
say 'The following files are on' dir1 'but not on' dir2
call show new, newi
end
exit
/* compare two date-time paris */
compdate: procedure
parse arg mm1 '/' dd1 '/' yy1 time1, mm2 '/' dd2 '/' yy2 time2
date1 = yy1||mm1||dd1||time1
date2 = yy2||mm2||dd2||time2
if date1 < date2 then
return -1
else if date2 < date1
then return 1
else
return 0
/* parse a file identifier */
parsedname: procedure
x = upper(arg(1))
parsed = parsefn(x)
if parsed = '' then
parsed = '- - - -'
parse var parsed drive path fn ft
if drive = '-' then
drive = dosdrive()
if path = '-' then
path = doscd(drive)
if right(path,1) \= '\' then
path = path'\'
if fn = '-' then
fileid = '*.*'
else if ft = '-' then
fileid = fn
else
fileid = fn'.'ft
return drive','path','fileid
/* display file names */
show:
line = ' '
do x = 1 to arg(2)
line = line left(value(arg(1)'.x'), 14)
if x // 5 = 0 then do
say line
line = ' '
end
end
if line \= '' then
say line
return
/* update a group of files */
replace:
do x = 1 to arg(2)
fname = value(arg(1).x)
say fname
'copy' dir2||fname dir1||fname
end
return