Home > Software engineering >  Batch | How to create several folders at same time
Batch | How to create several folders at same time

Time:02-04

I would like to create a folders (2021; if it doesn't exist) at the same time in sub directories of Users with a batch.

if not exist "C:\Users\abc\2021" ( mkdir C:\Users\abc\2021)
if not exist "C:\Users\def\2021" ( mkdir C:\Users\def\2021)
if not exist "C:\Users\uvw\2021" ( mkdir C:\Users\uvw\2021)
if not exist "C:\Users\xyz\2021" ( mkdir C:\Users\xyz\2021)

But I want to simplify it and tried the following:

if not exist "C:\Users\*\2021"  ( mkdir C:\Users\*\2021)

That didn't work. Where is the mistake and how is it correct?

CodePudding user response:

for /d %%u in ("C:\users\*") do if not exist "%%u\2021\*" md "%%u\2021"

should do what you appear to want to do. See for/? from the prompt for details.

  •  Tags:  
  • Related