-1

I was looking for batch script to create a new folder with incremental number.

Example:

DirectroryNames= 
DirectoryName_1_Label234_Date
DirectoryName_2_Label235_Date

I want to create a new directory every time batch script runs

DirectoryName_3_Label236_Date

next

DirectoryName_4_Label137_Date etc...

Any help ?

user2150777
  • 101
  • 1
  • 2
  • 6
  • Try [this question](http://stackoverflow.com/questions/12964356/increasing-numbers-over-100-batch-files?rq=1). – BDM Mar 12 '13 at 07:07

1 Answers1

0

Well, you could have two variables that both increase. Take a look at this snippet and see if you like it...

@echo off & setlocal enabledelayedexpansion
set start1=7
set start2=256
set end1=12
set end2=261
set /a amount=start2-start1

for /l %%i in (1,1,%amount%) do (
if DirectoryName_%start1%_Label1%start2%_Date exist goto end
md DirectoryName_%start1%_Label%start2%_Date
set /a start1+=1
set /a start2+=1
if %start1% geq %end1% goto end
)

:end
BDM
  • 3,760
  • 3
  • 19
  • 27
  • Thanks for the reply! When i run, i get error C:\File1> C:\File1>CreateDirectory.bat A subdirectory or file DirectoryName_7_Label256_Date already exists. – user2150777 Mar 12 '13 at 06:49
  • When i run, i get error C:\File1> C:\File1>CreateDirectory.bat A subdirectory or file DirectoryName_7_Label256_Date already exists. – user2150777 Mar 12 '13 at 06:50
  • Did you run the script more than once? – BDM Mar 12 '13 at 06:51
  • Yes , I want the directory name to increment the number – user2150777 Mar 12 '13 at 06:52
  • For Example: DirectoryName_1_Label234_Date DirectoryName_2_Label234_Date DirectoryName_3_Label234_Date – user2150777 Mar 12 '13 at 06:53
  • Well, there's you problem. It creates folders when it is run, if you run it more than once then there is going to be conflict. Delete the folders and do it again. It'll work. – BDM Mar 12 '13 at 06:54
  • ...But now that you mentioned it, I'll edit the script to end if there is already a file of that name. – BDM Mar 12 '13 at 06:55
  • ...Wait, do you mean every time it is run it creates another folder? – BDM Mar 12 '13 at 06:57
  • Yes, When ever i run the batch, it has to create the new directory with Name DirectorName_NextNumber_Label_NextNumber_%data% – user2150777 Mar 12 '13 at 06:58
  • Oh, while I create more code, please edit your question to reflect this. – BDM Mar 12 '13 at 07:00
  • This works for me, but i need the directory in DirectorName_NextNumber_LabelNextNumber_%date% http://stackoverflow.com/questions/13328421/how-do-i-increment-a-folder-name-using-windows-batch – user2150777 Mar 12 '13 at 07:07
  • So you want the directory of the folders...? – BDM Mar 12 '13 at 07:11
  • Script has to create the new Directories in DirectorName_NextNumber_LabelNextNumber_%date% format – user2150777 Mar 12 '13 at 07:22