Solved

Batch folder creation?

Posted on 2013-01-24
3
361 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 51

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 51

Expert Comment

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

~bp
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now