Batch folder creation?

Posted on 2013-01-24
Last Modified: 2013-01-24
I need to modify a DOS script, so that it:

1. creates one folder called 'documents' and within this folder, 3 more folders, where there's 400 folders that this needs to be applied to
2. count of how many folders the function was applied to
3. create a log file confirming success/ failure

I was previously provided the following script under the address:

How do I modify this, to achieve the above?

@echo off
set BaseDir=H:\Temp Folder\2013
set NewDirs="Excel","Powerpoint","Word"
  echo Making Directories...
  for /D %%A in ("%BaseDir%\*.*") do (
    for %%B in (%NewDirs%) do (
      md "%%~A\%%~B" >NUL 2>&1 && (
        echo Created: "%%~A\%%~B"
      ) || (
        echo *ERROR*: "%%~A\%%~B"
Question by:Osley
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 55

Accepted Solution

Bill Prew earned 250 total points
ID: 38813957
I think this should handle that change, let me know if you wanted a different count than the number of top level directories where you added these child directories.

@echo off
setlocal EnableDelayedExpansion

set BaseDir=H:\Temp Folder\2013
set NewDirs="Excel","Powerpoint","Word"
set LogFile=log.txt
set Count=0

  echo Making Directories...
  for /D %%A in ("%BaseDir%\*.*") do (
    set /A Count+=1
    md "%%~A\Documents" >NUL 2>&1 && (echo Created: "%%~A\Documents") || (echo *ERROR*: "%%~A\Documents")
    for %%B in (%NewDirs%) do (
      md "%%~A\Documents\%%~B" >NUL 2>&1 && (echo Created: "%%~A\Documents\%%~B") || (echo *ERROR*: "%%~A\Documents\%%~B")
  echo Processed !Count! Directories

Open in new window


Author Closing Comment

ID: 38813984
Awesome. Thanks. That did it very well.

Once again - much appreciated.
LVL 55

Expert Comment

by:Bill Prew
ID: 38814001
Happy to help, thanks for the feedback.


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question