Solved I need a .bat file to copy and rename a folder next in line.

March 16, 2015 at 10:02:58
Specs: Windows 7
Hi all,

Here goes, we have folders for each new assignment that comes in to our office, eg. 15-P0001, 15-P002, etc. There are multiple folders within each assignment folder. We have a template folder named 15-P0000 which we copy and rename with each new assignment number. I'm trying to create a .bat file which will copy the template folder (15-P0000) and then rename it the next available folder number (if the last folder was 15-P0036 then the next one would be 15-P0037). So the .bat file needs to search and find the last folder number used.

I asked this question yesterday but I didn't word it correctly, sorry about that.
Any help would be really appreciated!!!
nameci


See More: I need a .bat file to copy and rename a folder next in line.

Report •


✔ Best Answer
March 24, 2015 at 10:12:35
I figured it out. Removing the space between 15-P !ii! solved the issue.

@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 "15-P" "15-P!II!"
goto :eof
)
set /a I+=1
if /i %I% LSS 9999 goto NextI
)

Thanks to everyone who responded to my original question.



#1
March 16, 2015 at 20:39:33
Your homework assignment is to tweak the sequential folder script to do this.

It goes through and finds the lowest unused number.

=====================

M2 Get custom script or take private lessons

message edited by Mechanix2Go


Report •

#2
March 17, 2015 at 06:41:20
Thanks, will do :)

Report •

#3
March 18, 2015 at 07:39:19
Hi M2,

Where can i find the sequential folder script?? I look forward to trying to make it work for my purposes.

Thanks,


Report •

Related Solutions

#4
March 18, 2015 at 20:31:33
http://www.computing.net/answers/pr...

I usually put a shortcut to the thread in the folder where I'm working the script.

=====================

M2 Get custom script or take private lessons


Report •

#5
March 24, 2015 at 09:21:27
Hi M2,

I took your advice and dig my homework.

Here is what I ended up with.

@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 "15-P" "15-P !II!"
goto :eof
)
set /a I+=1
if /i %I% LSS 9999 goto NextI
)


My only problem is, the result is 15-P 0002, 15-P 0003, etc. Is there a way to eliminate the space between the P and 0, eg. 15-P0003??

Thanks in advance for any help that you can provide.


Report •

#6
March 24, 2015 at 10:12:35
✔ Best Answer
I figured it out. Removing the space between 15-P !ii! solved the issue.

@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 "15-P" "15-P!II!"
goto :eof
)
set /a I+=1
if /i %I% LSS 9999 goto NextI
)

Thanks to everyone who responded to my original question.


Report •

#7
March 24, 2015 at 13:32:15
Here is a new problem that I can't figure out. Some of or files have the customer name after the file number, eg. 15-P0025 Brown. How can I add to the script so it will pause and ask for user input to include the customer name or not??? This one has me stumped. Thanks in advance for any assistance.

@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 "15-P" "15-P!II!"
goto :eof
)
set /a I+=1
if /i %I% LSS 9999 goto NextI
)


Report •

#8
March 24, 2015 at 21:07:31
If you want to learn this stuff & become self-reliant use the built-in help.

set /?

is what you need right now.

=====================

M2 Get custom script or take private lessons


Report •

#9
March 25, 2015 at 06:15:04
Thanks, I just needed a direction to go. I'm enjoying trying to figure this out. Will post new batch once I have got it working. :)

Report •

#10
April 13, 2015 at 08:04:58
As promised, here is the final batch working the way that i want it too.

@echo off
setlocal enableDelayedExpansion
cd /d C:\Users\jbrown\Desktop\Test
set I=1
: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!*" (
set /p "client_name=OPTIONAL Enter a client name and press <ENTER>: "


xcopy /s /e /i "15-P0000-Template" "15-P!II!!client_name!"

goto :eof

)
set /a I+=1

if /i %I% LSS 999 goto NextI

Thanks again for all the help M2 :)


Report •


Ask Question