-1

How do I increment a folder name using Windows batch command?

I have multiple folders at some path in a particular format like Release Version(1.060) I want to create new folder with name - Release Version(1.063)

Laxmi
  • 83
  • 8
  • 3
    1. Why did you roll back the nice edit? 2. What have you tried, where are you stuck? 3. Why the tag [tag:window]? do you mean [tag:windows]? 4. Consider to use another language than batch scripting due to quite limited arithmetic functions... – aschipfl Jun 19 '19 at 11:22

1 Answers1

0

list the folders (/b = name only, /ad = folders only, /on = sort by name), get the version number with a for /f loop, add one to the minor number (note the trick to handle leading zeros: add a 1 in front of it, add one and get the last three chars). Then simply reassemble the new version number:

@echo off
for /f "tokens=2,3 delims=(.)" %%a in ('dir /b /ad /on "Release Version*"') do (
  set "major=%%a
  set "minor=1%%b"
)
set /a minor+=1
set "minor=%minor:~-3%"
echo new release version is "%major%.%minor%"
md "Release Version(%major%.%minor%)"

Of course, this depends on the exact format: Release Version(x.yyy).

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Not working. It displays an error - Parameter format not correct - ""Release Version*"". and creating Release Version(.1) folder. Also can you explain me this part of code - "minor=%minor:~-3%" – Laxmi Jun 20 '19 at 10:57
  • Works fine for me. Did you put it into a `(`command block`)`? Then you need [delayed expansion](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected/30284028#30284028). - `set "minor=%minor:~-3%"` sets the variable to the last three characters (cutting the leading `1`) – Stephan Jun 20 '19 at 11:02
  • sorry, spotted a missing space. Seems to got lost by editing `:/` Try edited code. – Stephan Jun 22 '19 at 20:16
  • Yes ,i realized the mistake and fixed it now its working fine..thanks a lot – Laxmi Jun 24 '19 at 05:20