Adding a sub folder to multiple directories where the name of the directories contains punctuation
I would like to create the same sub-directory in each directory of a folder. I found the answer here:
Add a new folder to each subfolder
The command prompt was:
FOR /d %A IN (e:\donuts\*) DO mkdir "%A\big"But perhaps because my director names contain spaces and commas, I end up with a bunch of directories based on the first word in each of the existing directories and a bunch of errors in the command prompt.
What variation can I use to allow for the fact that my directories have commas and spaces in the names?
32 Answers
You can use PowerShell!
Run this PowerShell command when you're in the folder whose subfolders should have the new folders added to them:
dir | ? {$_.PSIsContainer} | % {md ($_.FullName + '\New folder')}This lists the entries in the current folder (with dir, an alias for Get-ChildItem), then filters them (?) down to the ones that are folders. For each folder found, a new folder is created (md) with the full path as the path of the found subfolder plus a constant string, in this case \New folder, but you can set that to whatever you want, including things that have spaces and commas.
In PowerShell 3 and higher, it can be condensed to this:
dir -Directory | % {md ($_.FullName + '\New folder')}Here, dir takes an optional -Directory flag to only get folders.
To call this command from a batch script:
powershell -Command "dir | ? {$_.PSIsContainer} | % {md ($_.FullName + '\New folder')}" 3 You are just missing "" quotes on either end of the directory filename. So it would be:
FOR /d %A IN ("e:\donuts\*") DO mkdir "%A\big"