?
Solved

Batch folder creation?

Posted on 2013-01-24
3
Medium Priority
?
402 Views
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:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28006593.html

How do I modify this, to achieve the above?

@echo off
setlocal
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"
      )
    )
  )
)>"log.txt"
0
Comment
Question by:Osley
[X]
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
3 Comments
 
LVL 56

Accepted Solution

by:
Bill Prew earned 1000 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
)>"%LogFile%"

Open in new window

~bp
0
 

Author Closing Comment

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

Once again - much appreciated.
0
 
LVL 56

Expert Comment

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

~bp
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

777 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