(Yeah, still here. Having trouble finding a good (read, “free”) way to convert my archives.)
Way back in The Day, when the world was young and Windows NT 3.5 was my new operating system, Microsoft in their wisdom provided a disk full of neat utilities. Among them was a copy of a programming language I knew pretty well: REXX. Well, it was Regina, or what became Regina, but I digress. It was the Regina that had been ported to Windows (and I think unix as well — in fact unix might have been the original target, but I don’t remember) by Anders Christensen.
I learned REXX working on the IBM mainframe at school. The guy I went to work for in 1990-mumble was a REXX god. His name wasn’t Michael Cowlishaw but he probably could have taught Cowlishaw something about mainframes. Or not. But I digress.
Anyway, I’ve been programming in REXX for damn near half my life. On Windows it makes a great English-like scripting language that beats the hell out of DOS Batch-Command language. (Frankly, it beats hell out of unix shell command scripting, too. But I digress again.)
A number of years ago (I think about the time of the switch from NT 4.0 to Windows 2000), Microsoft suddenly stopped providing Regina on its “extras” disk. Which was probably a good thing, because what they were shipping was an old buggy version and you could get a nice new shiny working version from Mark Hessling. Which of course we’ve continued to use over the years for internal stuff.
So when my colleague in CS today asked me to fix his DOS script (you’ll excuse asterisks for the sake of obfuscation):
REM Product backup copy script
REM This bat-file maps a drive to G******…sorts the files by date that
REM are located on O*****’s E:\ProductUtil\Backup and copies over the
REM 3 **************** backup files to G******
net use Z: \\g******.***.*****.***\ProductBackupTest
pause 3
SET srcdir=E:ProductUtil\Backup
SET tgtdir=Z:
SET /A topcnt=3
SET /A cnt=0
FOR /F “tokens=*” %%F IN (‘DIR /B /A-D /O-D /TW “%srcdir%”‘) DO (
SET /A cnt+=1
SETLOCAL EnableDelayedExpansion
IF !cnt! GTR !topcnt! (ENDLOCAL & GOTO :EOF)
ENDLOCAL
COPY “%srcdir%\%%F” “%tgtdir%”
)
net use Z: /delete
I stared at that shite and said, “whuuuuttt???” And then wrote this instead:
/**/
srcdir = ‘E:\ProductUtil\Backup’
tgtdir = ‘Z:\’
tgtpath = ‘\\g******.***.*****.***\ProductBackupTest’
tempfile = srcdir’\COPYBACKUPS.TMP’
keep = 3
keepcnt=0/* write temp file */
‘DIR/B/A-D/O-D/TW ‘ srcdir’\*.ZIP >’ tempfile
If rc ^== 0 Then Exit/* map the tgtdir to tgtpath */
‘net use Z: ‘ tgtpath/* copy the first ‘keep’ files */
do while keepcnt < 3
line = Translate(Linein(tempfile))
If line == ” Then Leave
say ‘copy “‘srcdir’\’line'”‘ tgtdir
‘copy “‘srcdir’\’line'”‘ tgtdir
keepcnt = keepcnt + 1
end /* do */
call lineout tempfile/* unmap the tgtdir */
‘net use Z: /delete’/* delete temp file */
‘del’ tempfile
I had to tweak two things before I got it working — one, I forgot that I needed to fully-qualify the path to the file in the copy command (since it wasn’t running from the source directory, but rather, from a common scripts directory we maintain on the machine), and two, I didn’t know when I started that the files he was trying to copy had spaces in their names, so I didn’t originally double-quote the source file. Took 20 minutes to write and worked perfectly after the two tweaks mentioned. AND I can understand it when I read it.
Bottom line, it’s a shame that Microsoft didn’t adopt Regina as a shell scripting language. Then to compound the mistake, they devised that awful PowerShell abortion. Which I also now need to learn how to use.