Learned something...put the /I before the 'not'. Also that miskox' solution
is case insensitive, so .bat or .BAT get changed.
As a matter of curiosity, my time measurement test did not show any of these
three methods to have an advantage:
Code: Select all
@echo off
set "oFile=somefile"
set startTime=%time%
for %%i in (1,1,100000) do if /i not "%oFile:~-4,4%"==".BAT" Set "oFile=%oFile%.bat"
Echo If /i not... scenario start and end times: %startTime% - %time%
set "oFile=somefile.BAT"
set startTime=%time%
for %%i in (1,1,100000) do Set oFile=%oFile:.bat=%.bat
Echo remove and add back scenario start and end times: %startTime% - %time%
set "oFile=somefile"
set startTime=%time%
for %%i in (1,1,100000) Do (
for %%a in ("%oFile%") do if /i not "%%~xa"==".BAT" Set "oFile=%oFile%.bat"
)
Echo for loop with if /i not... scenario start and end times: %startTime% - %time%
If /i not... scenario start and end times: 8:28:54.37 - 8:28:54.37
remove and add back scenario start and end times: 8:28:54.37 - 8:28:54.37
for loop with if /i not... scenario start and end times: 8:28:54.37 - 8:28:54.37
Resolved and thankyou.