I am having the issue where my if statement (inside a for loop), doesn't seem to cooperate. What I am trying to do is this:
- Loop through a bunch of zip files and rename them 005.zip, 006.zip, 007.zip, etc.
- I keep a counter, starting at 5, that determines the file number, and a prefix that is 00 in order to get 005, 006, and so on.
- Once the counter reaches 10, I want the prefix to just be 0 instead of 00. So when the counter is ten, that file will be named 010.zip, and then 011.zip instead of 0010.zip, 0011.zip etc.
Here is what I have thus far:
setlocal enableextensions enabledelayedexpansion
SET /a COUNT=5
SET FILE_PREFIX=00
SET /a MAX=10
for %%f in (*.zip) do (
if !COUNT! == !MAX! (set FILE_PREFIX=0)
ren "%%f" %FILE_PREFIX%!COUNT!.zip
set /a COUNT+=1
echo !COUNT!
)
endlocal
Why doesn't the if statement work? The file renaming is working fine, it is just that if statement that doesn't change the FILE_PREFIX to 0.