I'm wondering if any of you could lend an assist with a small problem.
First, I'm under the impression I need to use Delayed Environment Variable Expansion (DEVE), based on other things I've read across the web.
Summary: trying to use command shell (cmd.exe) in XP sp3 (if that's relevant) to write a small script that will rename files.
So I require a for-loop that stores a filename for each iteration (simple enough, just use the %A in:
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "usebackq" in (`dir /b C:\directory\*`) do (
set origname=%A
echo %origname%
echo !origname!
)
which results in the literal strings "%origname%" and "!origname!" being printed to the screen, no variable expansion is taking place except in the line where I attempt to set the variable
origname...the %A expands to the iteration of the
`dir /b C:\directory\*` output which is being processed at the time.
What am I doing wrong?! From what I can tell, by other people's posts online, it seems like maybe DEVE isn't working for me, if !origname! won't expand to the value of %A after it's set in the first command of the command set for the loop operation.
I can't just use %A either, because I require string manipulation of the value %A and command shell is lame and can only perform string manipulaton of variables with the convention %var%, (e.g.
%var:~5,1% which would effectively extract the 6th char from the value of %var%.
I intend to perform checks of the 8th character in the %origname% variable and compare it against if test conditions to determine how to handle the file from there.
Make sense?!
I hope somebody here is familiar with DOS and can help me troubleshoot this. It's frustrating and I feel like I have found a cause in proving I'm smarter than esoteric DOS programming conventions.