Create folders one time only

July 9, 2009 at 20:21:36
Specs: win2k/xp
Let me start by saying two things;
1: I am a ROOKIE with batch files
2. thanks for any and all help I can get

I would like to create a batch file that checks if a specfic folder structure exsits (see structure at bottom of post) if any of the folders do not exist create ONLY the missing folders then delete the batch file (never run again). I assume I can put the batch file the Startup folder for all users and not use gpedit.msc since the batch file should run once and then never again
Folder structure;
d:\main folder
d:\main folder\folder 1
d:\main folder\folder 2
d:\main folder\folder 3
d:\main folder\folder 4
d:\main folder\folder 5

See More: Create folders one time only

Report •

July 10, 2009 at 00:01:01
I won't attempt self-modifying code, but thi shoud do the deed.

@echo off & setLocal enableDELAYedexpansion

for /L %%a in (1 1 5) do (
if not exist "d:\main folder\folder %%a" (
md "d:\main folder\folder %%a"

If at first you don't succeed, you're about average.


Report •

July 10, 2009 at 15:06:19
Thanks a lot, I did need to edit the batch file because the names and the amount of folders provided were examples, but I figured-out what (1 1 5) did and made adjustments (not all folders are sequential),

What would be really clean if I can create the folders based on a list within the batch file since some are consecutive and others are not to include a several have additional sub directories (see Building 30), this way as things change in the future the list is easily updated. I can help myself from here if is a problem once again thanks for all of your help, P.S. The actual directory structure looks more like this plus or minus a few in between but here is the gist of it;

d:\Building Folders\
d:\Building Folders\Building 2\
d:\Building Folders\Building 3\
d:\Building Folders\Building 4\
d:\Building Folders\Building 6\
d:\Building Folders\Building 7\
d:\Building Folders\Building 21\
d:\Building Folders\Building 30\30.1
d:\Building Folders\Building 30\30.2
d:\Building Folders\Building 30\30.3

Report •

Related Solutions

Ask Question