Solved

Batch folder creation?

Posted on 2013-01-24
3
373 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
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
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
)>"%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 52

Expert Comment

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

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now