This is commented code, for what matters.
/* REXX find cdrom */
/* Wendy Krieger - an OS2 fan 2 */
call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs' ; call sysloadfuncs
numeric digits 20 ;
parse arg opt string /* first word + rest of tail */
opt = changestr('/-:', opt, ' '); opt = strip(opt) /* remove -, /, etc from opt */
parse upper var opt with 1 kind 2 drive 3 . /* get kind of drive, and where to start */
if kind = 'C' then kind = 'CDROM'
if kind = 'R' then kind = 'RAMDISK'
if drive='' then drive=' '; drive = d2c(c2d(drive)+1) /* If the user says c: we look for d: and larger */
gamma = SysDriveMap(drive, kind) /* get the next drive */
gamma = left(gamma, 1) /* loose the colon */
if gamma = '' then gamma = ' ' ; erl = c2d(gamma) // 32 /* errorlevels: A=a=1, B=b=2, C=c=3, etc */
parse var string 1 letter 2 string /* here, for $cdrom=$: , the prog reads the first $, and replaces later $ with the letter desired */
string = changestr(letter, string, gamma) /* this is the replacement */
if letter='@' then do /* magic for processing environments */
parse var string environ'='newstr
if erl = 0 then newstr= ''
aa = value( environ, newstr, 'SYSTEM') /* works in 4nt, not in cmd */
call lineout, 'set' environ'='newstr ; end /* still produces SET environ=value */
else if erl > 0 then call lineout, string /* print the string if there is a drive */
exit erl /* return a value for ERRORLEVEL: A=a=1, B=b=2, etc */
When one looks for a cdrom, one can not suppose that the first cdrom is the real one, or that it's the interesting one. Suppose that you have the hardware cdrom in S: (where OS/2 puts it). Now. You might have programs like virtualcd that can mount an iso at a different position(s) (say O: and E: or whatever).
So if you look for the first cdrom, you will get E: in this example. This is not the disk you might be looking for, so you search again, for a letter, like 'O'. This program allows you to do this, by "cdrom.rex c%cdrom% @cdrom=@: " Because the search begins at %cdrom% (ie E:), it produces the next result F or later. It will give then O: next. A further search reveals the correct drive S:. This is why i included the 'search from' thing.
The second bit is about getting the environment letter. The script attempts to set the current environment. In 4nt, it works, the value is set directly. However, in cmd, it sets the environment that regina inherits, but is not passed back to cmd's environment. This is why we have to do things like produce a redirectable string. An environment value is created for redirection to a batch file, which can then be called. If there is no further drive, the line is produced with a null value, eg "SET CDROM=". This removes the value from the environment.
Error levels are supported, so if there is no drive reported, one gets an errorlevel of 0. Otherwise, the errorlevel is the drive number, in line with the DOS findcd and findram utilities.
One could add support for other kind of drives, like removable (not cdrom), fixed drives etc. This just amounts to adding an extra letter at 'if kind= 'M' then kind='REMOVABLE' etc. This is documented in the SysDriveMap command in the .PDF. Searching for removable drives might detect floppy disks and usbs if these are seen as removable.
You can register .rex scripts in the PATHEXT. If you use rexx a lot, it's quite useful. Patrick McPhee's W32UTILS is a welcome extension that gives regina access to the registry, including loading and unloading things, creating icons, etc. You could, for example, use it to create a desktop from a single script similar to this.
I have a script, of slightly different nature, using Frank P Westlake's excelent utility conset.exe. This utility will read things from registry into the current environment. This script, allows you to change to some shellfolder directory (similar to typing shell:folder in the run dialog). So, eg cdf desktop will change to the desktop.
You can use the same thing to open your own folders, or if you mount a foreign registry in the same position, to its folders. Note that i add my own shell-folders at "HKLM\Software\Wendy\Folders". So "cdf batch" changes to the batch folder.
You can open the file in registry too, with the /m(achine), /u(ser) and /w(endy) switches. The reg: protocol can be handled either by Sysinterns 'regjump' utility, or the 'regmagik' program.
@echo off
:: cd shell folder.
set zdir=
set zshf=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
set zcmd=chdir
set zhere=%*
if "%1"=="/o" set zcmd=open
if "%1"=="/o" set zhere=%zhere:~3%
conset /q /k zdir=HKLM\%zshf%\%zhere%
if not "%zdir%"=="" goto :doit
conset /q /k zdir=HKCU\%zshf%\%zhere%
if not "%zdir%"=="" goto :doit
conset /q /k zdir=HKLM\Software\Wendy\Folders\%zhere%
if not "%zdir%"=="" goto :doit
if /i "%1"=="/m" goto :hklm
if /i "%1"=="/u" goto :hkcu
if /i "%1"=="/w" goto :hkwe
goto :end
:hklm
shelexec reg:hklm\%zshf%
goto :end
:hkcu
shelexec reg:hkcu\%zshf%
goto :end
:hkwe
shelexec reg:hklm\software\wendy\folders
goto :end
:doit
set zcxm=
if %zcmd%==chdir cd /d %zdir%
if %zcmd%==open shelexec %zdir%
set zdir=
:end