Add more multiple folders in a specific location (SOLVED)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Add more multiple folders in a specific location (SOLVED)

#1 Post by newbie » 29 Sep 2010 01:50

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
Last edited by newbie on 17 Oct 2010 09:50, edited 1 time in total.

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Add more multiple folders in a specific location

#2 Post by amel27 » 29 Sep 2010 03:40

newbie wrote:But the thing is I want to add more folders into that specific location (folder). How?
sorry, but I've badly understood you... try this:

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

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#3 Post by newbie » 04 Oct 2010 00:21

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Add more multiple folders in a specific location

#4 Post by amel27 » 04 Oct 2010 03:26

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?

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#5 Post by newbie » 04 Oct 2010 18:23

Can you show me your result??

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#6 Post by newbie » 04 Oct 2010 18:49

Thanks a lot it works fine!!!!! :D :D :D :D

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#7 Post by newbie » 04 Oct 2010 19:52

Sorry to disturb u again, can u explain to me how the codes work as I can see $i,%%,>,nul,~, tq very much..

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Add more multiple folders in a specific location

#8 Post by amel27 » 05 Oct 2010 05:17

$i - temporary variable for processed folder (name)
"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

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#9 Post by newbie » 05 Oct 2010 21:30

thanks a lot!!!

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#10 Post by newbie » 05 Oct 2010 22:59

what if I want to delete some of the folders but automatically updating the folder's count number??

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Add more multiple folders in a specific location

#11 Post by amel27 » 06 Oct 2010 02:52

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

newbie
Posts: 24
Joined: 29 Sep 2010 01:30

Re: Add more multiple folders in a specific location

#12 Post by newbie » 17 Oct 2010 09:35

Thnx :D

Post Reply