Windows – Batch create subfolders in path with spaces

batch filewindows 7

I'm trying to create a subfolder 2015 in many project folders on a shared drive. A previous post here already explained perfectly how to do this using CMD: here. This solution said:

FOR /d %A IN (e:\donuts\*) DO mkdir %A\big

My problem is that the path to the project folders in which the 2015 subfolder will be created contains spaces. So my code looks like this

FOR /d %A IN (e:\corporate folder\*) DO mkdir %A\2015

Where the project folders project1, project2, projectn are found in place of the *. When I run this, CMD interprets this as:

mkdir e:\corporate\2015 

resulting in a folder:

e:/corporate/2015

When I create a dummy folder on the same drive and run:

FOR /d %A IN (e:\corporate_folder\projects\*) DO mkdir %A\2015

a 2015 folder is created in each subfolder, as it should be. From this I conclude that space in the folder path causes the problem. I'd appreciate any suggestions to force CMD to accept the space as part of the path. Thanks!

Best Answer

Enclose the path reference in quotation marks:

FOR /d %A IN ("e:\corporate folder\*") DO mkdir "%A\2015"
Related Question