Add more multiple folders in a specific location (SOLVED)
Moderator: DosItHelp
Add more multiple folders in a specific location (SOLVED)
Hi guys, I'm really new to batch file and I really need help. I created a batch file that can create multiple folders and I put it in a specific location (folder). That's fine. But the thing is I want to add more folders into that specific location (folder). How??
This is the code:
@echo off
cls
echo ----------------------------------------------------------
echo How many folders you want to create?:
echo 1. Start to create folders if you want to start from (1)
echo 2. Start to create folders from any number (2,3,4,...etc)
echo 3. Exit/Quit
echo ----------------------------------------------------------
set /p menu="Please select the options given above: "
if %menu% == 3 goto exit
if %menu% == 1 goto satu
if %menu% == 2 goto dua
:satu
set /p nama="This is to create how many folder you want?(for example, if "10", then it will be 1-10 2-10 3-10 ...): "
set /p name="If you would like to create a new folder to keep all your folders, please specify the name of the new folder here (add "" to give space between words): "
set count=0
set dash=-
:loop
set /a count=%count%+1
md %name%\%count%%dash%%nama%
if %count% == %nama% goto exit
goto loop
This is the code:
@echo off
cls
echo ----------------------------------------------------------
echo How many folders you want to create?:
echo 1. Start to create folders if you want to start from (1)
echo 2. Start to create folders from any number (2,3,4,...etc)
echo 3. Exit/Quit
echo ----------------------------------------------------------
set /p menu="Please select the options given above: "
if %menu% == 3 goto exit
if %menu% == 1 goto satu
if %menu% == 2 goto dua
:satu
set /p nama="This is to create how many folder you want?(for example, if "10", then it will be 1-10 2-10 3-10 ...): "
set /p name="If you would like to create a new folder to keep all your folders, please specify the name of the new folder here (add "" to give space between words): "
set count=0
set dash=-
:loop
set /a count=%count%+1
md %name%\%count%%dash%%nama%
if %count% == %nama% goto exit
goto loop
Last edited by newbie on 17 Oct 2010 09:50, edited 1 time in total.
Re: Add more multiple folders in a specific location
sorry, but I've badly understood you... try this:newbie wrote:But the thing is I want to add more folders into that specific location (folder). How?
Code: Select all
@echo off
setlocal enabledelayedexpansion
set /p nama="How many new folders you want?: "
set /p name="Enter path to root folder: "
if not exist "%name%" set count=0& md "%name%" 2>nul
if not exist "%name%" echo Error creating root folder.& pause& exit /b 1
pushd "%name%"
for /d %%i in (*-*) do (
set $i=%%~ni
if not defined count set count=!$i:*-=!& set /a nama+=!count!
call ren "%%i" %%$i:-!count!=-!nama!%%
)
set /a count+=1
for /l %%a in (%count%,1,%nama%) do md %%a-%nama%
popd
Re: Add more multiple folders in a specific location
As you can see above, i have menus and if I pick "1", it will create how many folders I want and place the folders on another folder that I created using this batch file, so let say I have created "5" folders on "test" folder and it will be "1-5 2-5 3-5 4-5 5-5" on "test" folder, so I want to add more folders (for example I want to add 3 more folders) on "test" folder and I want it to be "1-8 2-8 3-8 4-8 5-8 6-8 7-8 8-8", so in this case it automatically updated the folders on "test" folder, if im using your given code, it will add folders but it will just count like this: "1-5 2-5 3-5 4-5 5-5 1-3 2-3 3-3" , so I really hope that you can help me to figure this out..tq
Re: Add more multiple folders in a specific location
newbie wrote:if im using your given code, it will add folders but it will just count like this: "1-5 2-5 3-5 4-5 5-5 1-3 2-3 3-3" , so I really hope that you can help me to figure this out..tq
hm... in my several tests on XP/2003 result folders after 5/test + 3/test input is: "1-8, 2-8, 3-8, 4-8, 5-8, 6-8, 7-8, 8-8"
whether there were some error messages in runtime?
Re: Add more multiple folders in a specific location
Can you show me your result??
Re: Add more multiple folders in a specific location
Thanks a lot it works fine!!!!!
Re: Add more multiple folders in a specific location
Sorry to disturb u again, can u explain to me how the codes work as I can see $i,%%,>,nul,~, tq very much..
Re: Add more multiple folders in a specific location
$i - temporary variable for processed folder (name)
"2>nul" supress some error mesage by MakeDir
above code with short comment
"2>nul" supress some error mesage by MakeDir
above code with short comment
Code: Select all
@echo off
setlocal enabledelayedexpansion
set /p nama="How many new folders you want?: "
set /p name="Enter path to root folder: "
:: Check destination folder, if not exist:
:: - create folder
:: - set folder counter COUNT=0
if not exist "%name%" set count=0& md "%name%" 2>nul
:: If destination folder not exist - echo error mesage & Exit
if not exist "%name%" echo Error creating root folder.& pause& exit /b 1
:: Make destination folder as current
pushd "%name%"
:: Enum old subfolders by mask "*-*"
:: On first loop:
:: - calculate old count of folders (right part of name) to var COUNT
:: - calculate new count of folders to var NAMA=NAMA+COUNT
:: On each loop:
:: - replace right part of each folder name from %count% to %nama%
:: via RENAME command
for /d %%i in (*-*) do (
set $i=%%~ni
if not defined count set count=!$i:*-=!& set /a nama+=!count!
call ren "%%i" %%$i:-!count!=-!nama!%%
)
:: Create additional subfolders
set /a count+=1
for /l %%a in (%count%,1,%nama%) do md %%a-%nama%
:: restore current folder
popd
Re: Add more multiple folders in a specific location
thanks a lot!!!
Re: Add more multiple folders in a specific location
what if I want to delete some of the folders but automatically updating the folder's count number??
Re: Add more multiple folders in a specific location
newbie wrote:what if I want to delete some of the folders but automatically updating the folder's count number??
it skipped, as a constant "hole", because right number use for enumerate