Dias de verano, using the variable modifiers as you demonstrated will no doubt work very handily in most cases. I am anxious to hear from DaveLembke to see if he got his script working. Please let us know Dave!
I had a similar problem that requires a bit more complicated approach. I'm not sure from DaveLembke's post whether he needs the straight forward approach you suggested, or if his situation is more like mine.
I have a program that I want to run from the usb drive on several different machines. The problem I run into, occurs because the program I am running "remembers" numerous previous settings relating to drive & path locations. Since the lowest available drive letter is different on each machine, the program would get lost every time I switched machines. Then I had to change numerous settings each time. A real pain!
It seemed like a good idea to find a way to search for the thumb drive and substitute the drive path with the letter Z:
I have resolved the problem with a very long & cumbersome routine. Although my routine works well, it is very long!!!
I am hoping that one of you guys would have a simpler approach. I've been waiting for the right opportunity to ask, and right now seems right.
Here is a portion of the routine, that I came up with, so you can see what I am doing. (In order for this to work, the folder being searched for must have a very unique name that won't be found accidentally anywhere else.)
:FIND_DRIVE
:: Find your drive letter, then ...
:: substitute the drive and path with "Z:"
:: [Substitute the "User Program Files" folder(and sub-folders) to a virtual drive "Z:"]
:IF_Z_DRIVE
if not exist "Z:\User Program Files\Unique Folder\." goto IF_Y_DRIVE
goto Z_DRV_ERROR
:IF_Y_DRIVE
if not exist "Y:\User Program Files\Unique Folder\." goto IF_X_DRIVE
subst Z: "Y:\User Program Files"
goto PROGRAM
:IF_X_DRIVE
if not exist "X:\User Program Files\Unique Folder\." goto IF_W_DRIVE
subst Z: "X:\User Program Files"
goto PROGRAM
:IF_W_DRIVE
......
......
......
:: NOTE: The four lines were repeated 21 more times to repeat the search for every drive letter through C:.
:: All sections were similar except that the first and last section returns an error, rather than substituting a drive letter.
:: In this example I wanted to see only the "User Program Files" folder in the virtual drive. If you want to see the entire drive, the subst line would be changed to:
subst Z: "Y:\." ... subst Z: "X:\." and so on to indicate the root of the usb drive.
......
......
......
:IF_D_DRIVE
if not exist "D:\User Program Files\Unique Folder\." goto IF_C_DRIVE
subst Z: "D:\User Program Files"
goto PROGRAM
:IF_C_DRIVE
if not exist "C:\User Program Files\Unique Folder\." goto NODRV_ERROR
subst Z: "C:\User Program Files"
goto PROGRAM
By the way, this code does not require that the batch file be located on the usb drive to work. It runs the same located there as when run from a copy on the desktop.
If you want to see the whole thing, error messages and all, I could either post it or attach it as a text file. But...
what I am hoping instead is that one of you guys will have a simpler approach.