Solved

Batch folder creation?

Posted on 2013-01-24
3
387 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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 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