I am trying to do something nearly identical to this: How do I increment a folder name using Windows batch?
Essentially, I want to create a batch file to scan through a directory, determine the highest version number, and then create the next one in sequence. So if the directory contains:
New folder V1.0
New folder V1.1
New folder V1.3
I want the batch file to add a New folder V1.4. Should be doable. The problem is that the script I found:
@echo off
setlocal enableDelayedExpansion
set "baseName=New_Folder"
set "n=0"
for /f "delims=" %%F in (
'2^>nul dir /b /ad "%baseName%*."^|findstr /xri "%baseName%[0-9]*"'
) do (
set "name=%%F"
set "name=!name:*%baseName%=!"
if !name! gtr !n! set "n=!name!"
)
set /a n+=1
md "%baseName%%n%"
doesn't work with folders with spaces in the name IE it works with 'New_Folder' but not 'New Folder'. I've tried escaping the spaces with various permutations of ^ and ", for example,
set "baseName=New^ Folder"
set "baseName=New" "Folder"
set "baseName=New""^ ""Folder"
and so forth, however, I haven't gotten it to work.
I am aware that I could solve the problem by changing my file names to use underscores, but at this point, I want to know why it doesn't work and how to fix it.