set from="C:\test"
set trim="Microsoft "
call :fTrim
And the directory:
C:\test\Microsoft Excel.lnk
C:\test\Microsoft Word.lnk
C:\test\Office.lnk
C:\test\subdir\Microsoft Outlook.lnk
Results in:
C:\test\Excel.lnk
C:\test\Office.lnk
C:\test\Word.lnk
C:\test\subdir\Outlook.lnk
I have the following:
Code: Select all
:fTrim
for %%f in (%from%) do (
for /F %%i in ('dir /b /s %%f\%trim%*.*') do (
set newvar=%%~nxi
rem The following line works:
rem set newvar1=!newvar:Microsoft =!
rem The following line, which uses the variable, doesn't work:
set newvar1=!newvar:%trim%=!
echo Orig: "%%i" New: "!newvar1!"
)
)
I'd use a static string of "Microsoft " if I didn't need to change it, as to "Creative " for renaming things from Creative Labs (tm). I've tried substituting %trim% with !trim!, `!trim!`, but still can't seem to get 'set' to understand the variable.
Note that in order for 'for' to understand:
for /R %from% %%i in (%trim%*.*) do (
some contortions were needed. I used a shortcut for:
for /F "usebackq ...
which happens to work quite well and produces the recursive directory listing fine.
How do I get DOS under Windows 2000 to understand the %temp% so I can do: rename "Microsoft *.*" "*.*" and get it to understand it needs to strip out the "Microsoft " or "Creative " or other variable string?