1

I am planning to create some kind of archive. Suppose I have these set of folders a = {A, B, C, D} And I have another collection of folders like b = {1, 2, 3, 4}

Now, how I can create folders using a .bat file such that every folder in "a" has the "b" folders. Meaning that every folder in "a" should have "1, 2, 3, 4" as sub folders.

I tried to do something using xcopy but it did not work.

1 Answer 1

2

This works for me on windows 7:

for %%a in (A,B,C,D) do (
    for %%i in (1,2,3,4) do (
       mkdir  %%a\\%%i
    )
)  

To answer your question about a more general script; put this into a batch file such as a.bat and run that.

@echo off
rem the directory where I wish to make subdirectories
set mypath=C:\Users\Philip\AppData\Local\Temp\Test

rem go to that directory
cd /d %mypath%

rem the names of subdirectories I want to create for each directory (no outer quotes)
set mydirs=ralph,john,sally,betty,11,22

for /f %%a in ('dir/b/ad') do (
    for %%i in (%mydirs%) do (
        if not exist %%a\\%%i (
            mkdir %%a\\%%i 
        )
    )
)  

If you want only a subset of directories you can change the outer for to use wildcards. E.g. only directories that start with C

for /f %%a in ('dir/b/ad C*') do (
Sign up to request clarification or add additional context in comments.

1 Comment

That worked perfectly fine! Thank You! But I have a further question, is there a way to not specify A, B, C, D? Like using a star (*) ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.