Solved .bat to create multiple new folders + add to context menu :o

January 13, 2012 at 16:01:46
Specs: Windows Vista64, Q9450, 4GB RAM

I want to create a .bat file that when placed and run in a directory, will create new folders there. It would need to prompt me to specify the number of folders to create, eg. 'folders to create...' and automatically number them from 1 upwards.

In an absolutely ideal world, I would like to be able to dump that .bat in c:\WINDOWS and make a .reg that will add a 'folders to create...' entry to my context sensitive menu and then run the .bat that way.

I'm totally new to .bat files and would have to cannibalise other peoples files to create this script and probably wreck my PC in a trial and error process :D

A little help would be appreciated. Maybe a lot of help.

See More: .bat to create multiple new folders + add to context menu :o

January 14, 2012 at 03:37:45
try this
@echo off
md c:\x\01
md c:\x\02
md c:\x\03
md c:\x\04

Report •

January 14, 2012 at 06:58:03
Hi chinmaya hotta,

It seems I would have to replace the 'x' with the complete destination folder location and manually enter folder names. It doesn't create in the location it is run from, but thanks for trying.

As an example of what I mean, here is a little .bat (PrintDir.Bat) that prints the contents of the folder from which it is run to a .txt file:

@echo off
dir %1 /-p /o:gn > "%temp%\Listing"
start /w notepad "%temp%\Listing"

But it can also be placed in C:\WINDOWS\ and then the below .reg (PD_Reg.reg) modifies the registry and adds an entry to the context menu, so that when you right-click on a folder the option 'print directory listing' appears in the context menu and prints the contents of said folder to a .txt:

Windows Registry Editor Version 5.00


[HKEY_CLASSES_ROOT\Directory\Shell\Print_Directory_ Listing]
@="Print Directory Listing"

[HKEY_CLASSES_ROOT\Directory\shell\Print_Directory_ Listing\command]
@="PrintDir.bat \"%1\""


[HKEY_CLASSES_ROOT\SOFTWARE\Classes\Directory\shell \Print_Directory_Listing]
@="Print Directory Listing"

[HKEY_CLASSES_ROOT\SOFTWARE\Classes\Directory\shell \Print_Directory_Listing\command]
@="PrintDir.bat \"%1\""

[HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell \AttachmentExecute\{0002DF01-0000-0000-C000-000000000046}]


It's a handy little script, and I was hoping that something similar could be made to create multiple folders: it appears in the context menu when you right-click a folder; then when it runs, it prompts you to specify the number of folder to create; then creates them in said folder, numbering them arbitrarily 01 upwards, or 1 upwards--whatever is easiest.

Sadly it's a bit beyond me :(

Report •

January 15, 2012 at 19:21:03
✔ Best Answer
This is do-able. Try this:

@echo off
REM loading the output of cd into tmp.tmp (current directory)
cd > tmp.tmp
REM setting variable curdir equal to contents of tmp.tmp (current directory)
set /p curdir=<tmp.tmp
REM getting desired number of folders from user
set /p numfolders="How many folders do you want to create?"
REM setting incremental variable for folder naming
set incr=0
REM incrementing incremental variable by one
set /a incr=%incr% + 1
REM checking to see if incremental variable has exceeded users desired number of directories, if so, goto end
if %incr% gtr %numfolders% goto end
REM making incremented directory
md "%curdir%\%incr%"
goto makefolders
REM quietly deleting tmp.tmp
del /Q tmp.tmp

Report •

Related Solutions

January 16, 2012 at 05:46:10
Awesome, that works like a charm. Thank you very much, jowah. Makes filing a lot easier.

I'll see if I can get it working through the context sensitive menu (not sure if possible), lots of registry backing up in my future ;)

Report •

Ask Question