Creating filenames automatically with X and Y

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zebzz
Posts: 2
Joined: 28 Jun 2020 16:01

Creating filenames automatically with X and Y

#1 Post by zebzz » 28 Jun 2020 16:09

Hi,

I am trying to write a batch script were i will prompt for a 'X' and 'Y' value. I then need to generate files from a single file.

I need to have something like this:-

filename_X01_Y01.xxx
filename_X01_Y02.xxx
filename_X01_Y03.xxx
filename_X01_Y04.xxx
filename_X02_Y01.xxx
filename_X02_Y02.xxx
filename_X02_Y03.xxx
filename_X02_Y04.xxx

The idea is that i need to create all files with all variations of X and Y so if you have value X = 20 and value Y = 20 this would generate 420 files.

At the moment I am generating the names in excel and then pasting them into the batch file. This would then add 420 commands and would be static in the number of files. I would like to have the option to generate a variable amount based on X and Y value.

Any help would be appreciated. :D :D :D

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Creating filenames automatically with X and Y

#2 Post by Aacini » 28 Jun 2020 21:14

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Read last values
set /P "lastX=X = "
set /P "lastY=Y = "

rem Generate the desired names
set /A X=100
for /L %%X in (1,1,%lastX%) do (
   set /A X+=1, Y=100
   for /L %%Y in (1,1,%lastY%) do (
      set /A Y+=1
      echo filename_X!X:~1!_Y!Y:~1!.xxx
   )
)
Antonio

zebzz
Posts: 2
Joined: 28 Jun 2020 16:01

Re: Creating filenames automatically with X and Y

#3 Post by zebzz » 29 Jun 2020 08:10

Thank you for your help, great and simple file generation process. Just could not get my head around the process. :D :D :D :D :D :D

Post Reply