Isn't there a way to use wildcards? like if exist c:\*\*\*\*\test_folder mkdir c:\*\*\*\*\test_folder ?
Main Topics
Browse All TopicsI need to create a folder (if it doesn't already exist) in a subdirectory that is 5 levels deep without having to specify the path. Reason is because I need to do this with several directories.
I'm not sure if this can be done using FOR in a batch script, or if it can be done using something like VBS. I'm trying to search for my answer, but haven't had much luck so far so I thought I'd turn to the experts for help :)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I just tried that and it doesn't work, I think in dos scripting anyways you'll need to do alot of IF statements to check all the possible locations, there should be a way to set this to do it recursively, but I haven't given it enough thought to actually write the code - I am sure it can be done to search a hard drive and if the directory doesn't exist then to create it ...
It would look something like this. we'll use c:\ as the root
c:\1\a\b\c\d\e\test_folder
c:\2\f\g\h\i\j\test_folder
c:\3\t\u\v\w\x\test_folder
etc
So what i'm trying to do is traverse 5 levels beneath each directory in the root of c:\ and check if test_folder exists. If it doesn't, create it.
of course c:\ isn't the root directory i'm wotking with. Each folder in the actual root directory will always have a minimum of 5 levels.
Hope this explains things a bit better.
Try the script below.
It will currently only pretend to create the folders, that is, instead of creating the folders, it will print out the "md" commands it would normally run, so that you can test and adjust the settings, if necessary. Once you've tested it, simply remove the capitalized ECHO.
The level count is *absolute* from the root of the drive, so in your "wildcard" example above, it would actually be 5, but for "c:\1\a\b\c\d\e\test_folde
Paste the script below into a text file with a .vbs extension. Customize the value of the strRoot variable on line 1 with the location of the folder to search under. Do not include a trailing backslash.
Customize the value of the strNewFolder variable on line 2 with the name of the new folder to create.
Running the script will echo the paths of the folders to create. Once you have tested it successfully and are certain it will do what you intend, remove the apostrophe from line 25 to create the folders.
5 levels deep. Remove the echo to have it actually do the create folder.
For your example:
ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set StartFolder=C:
Set CreateFolder=Test_Folder
for /f "tokens=1-7 delims=\" %%a in ('dir /ad /s /b') do (
if "%%g" NEQ "" if not exist "%%a\%%b\%%c\%%d\%%e\%%f\%
)
Business Accounts
Answer for Membership
by: TBK-ConsultingPosted on 2009-11-04 at 08:33:46ID: 25741041
somehow or other eventually you will need to specify the path in order to create the directory ... otherwise how does the program know where to create the directory - it just isn't logical without telling it where it needs to be created ... now if you are not sure where to create the directory because it could be in one of say 12 locations, then you would need to use variables of some sort to hold the various pieces of the path to put together when the time comes to create the sub-directory ... IE -->
md \\<computername>\\<directory 1>\<subdir 2>\<subdir 3>\<subdir 4>\<subdir 5>\<new subdir name>
the variables can be gathered by any means if-then statements to determine which path or what have you ...