Batch to add user input to the end of a folder name??

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nameci
Posts: 1
Joined: 26 Mar 2015 10:16

Batch to add user input to the end of a folder name??

#1 Post by nameci » 26 Mar 2015 10:21

Hi All,
First post here :) I am new to creating batch files and have created the below batch file. Basically, when we get a new assignment we copy the template folder and then rename it the next unused folder name, eg. if the last folder was 15-P0028 the next one would be 15-P0029. the batch works perfectly! But, sometimes we want to add a client name to the end of the folder name, eg. 15-P0029 Brown. I want the batch to pause for user input after renaming the folder the next in sequence so we can enter a client name or just hit enter to insert the new folder without the client name.
Can anyone help me with this, it would be greatly appreciated :D


Code: Select all

@echo off
setlocal enableDelayedExpansion
cd /d C:\Users\jbrown\Desktop\Test
set I=2
:NextI
if /I %I% LEQ 999 set II=0%I%
if /I %I% LEQ 99 set II=00%I%
if /I %I% LEQ 9 set II=000%I%
if not exist "15-P!II!" (
xcopy /s /e /i "15-P0000-Template" "15-P!II!"
goto :eof
)
set /a I+=1
if /i %I% LSS 9999 goto NextI
)
Last edited by Squashman on 26 Mar 2015 15:25, edited 1 time in total.
Reason: MOD EDIT: Please use CODE TAGS.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to add user input to the end of a folder name??

#2 Post by aGerman » 26 Mar 2015 17:33

Try the following code:

Code: Select all

@echo off &setlocal EnableDelayedExpansion
cd /d "%userprofile%\Desktop\Test"

set "I=0000"
for /d %%i in (15-P*) do (
  set "folder=%%i"
  set "currI=!folder:~4,4!"
  if !currI! gtr !I! set "I=!currI!"
)

echo latest: %I%

set /a "I=1%I% + 1"
if %I% gtr 19999 (
  echo Maximum number reached.
  pause
  exit /b
)

set "client="
set /p "client=Enter client name (optional): "
if defined client set "client= %client%"

xcopy /sei "15-P0000-Template" "15-P%I:~-4%%client%"

Regards
aGerman

Post Reply