Create multiple subfolders...

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Create multiple subfolders...

Post by MigrationUser »

12 Mar 2010 16:52
David W. Weekley

I have a need to create many folders. I have one folder with 1500+ beneath. I need to add one folder 'MFGPLAN' within each of the 1500+. Can ROBOCOPY do this? FYI...There are other folders within those.

David

----------------------------

#2 13 Mar 2010 08:16
Chimaera


Not sure you need robocopy

Possiblly try MD

C:\temp> MD MFGPLAN
will create your folder within the temp folder, you will ned some kind of code to identify and add the folders in the right place, possibly a check that the folder is there or not, and using IF add the folder when its not.

https://ss64.com/nt/if.html
https://ss64.com/nt/md.html

----------------------------

#3 13 Mar 2010 12:45
bluesxman


Chimaera is pointing you in the right direction; I believe this is the sort of thing you're after (untested)...

From the command prompt:

Code: Select all

for /d %a in ("X:\yourDirectory\*") do mkdir "%~fa\MFGPLAN" 2>nul
Or within a script:

Code: Select all

for /d %%a in ("X:\yourDirectory\*") do mkdir "%%~fa\MFGPLAN" 2>nul
Last edited by bluesxman (13 Mar 2010 12:45)

cmd | *sh | ruby | chef

----------------------------

#4 13 Mar 2010 17:20
David W. Weekley


Thanks for the assist. I will have to test this on my PC first. Question...can you tell me where I can get some explaination for the code you furnished? I would like to educate myself abit on it.

Thanks

----------------------------

#5 13 Mar 2010 18:14
Chimaera


from here

https://ss64.com/nt/

----------------------------

#6 14 Mar 2010 11:10
Simon Sheppard


Just for comparison heres how you could do this in Powershell:

Code: Select all

# Get all the folder names and store in $folders
$folders = gci 'C:\YourDir' | Where-Object{($_.PSIsContainer)} | foreach-object{$_.Name}

# In each folder create the subfolder
ForEach($fldr in $folders){ New-Item -ItemType Directory -Path "C:\YourDir\$fldr\MFGPLAN"}
The PS version is a bit more verbose than a one line FOR command, but it may be easier to follow how it works.

Also I've edited the title of this thread so people searching don't think its a robocopy thread

----------------------------

#7 14 Mar 2010 15:15
David W. Weekley


Thanks for the assist. I can look thru the script and understand what it is going to do. Have not had any experience with PowerShell. I opened it thru 'Run' and opens like the 'CMD' window. Am I merely copying and pasting this into the window? I setup a series of folders on my workstation to run first before I attempt on the server.

David

----------------------------

#8 14 Mar 2010 20:47
Simon Sheppard


You can run powershell from a script (.ps1) or just paste the commands at the PS: > prompt

----------------------------

#9 15 Mar 2010 12:36
jumper
Simon Sheppard wrote:

Just for comparison heres how you could do this in Powershell:

Code: Select all

    # Get all the folder names and store in $folders
    $folders = gci 'C:\YourDir' | Where-Object{($_.PSIsContainer)} | foreach-object{$_.Name}

    # In each folder create the subfolder
    ForEach($fldr in $folders){ New-Item -ItemType Directory -Path "C:\YourDir\$fldr\MFGPLAN"}
The PS version is a bit more verbose than a one line FOR command, but it may be easier to follow how it works.

Also I've edited the title of this thread so people searching don't think its a robocopy thread
or

Code: Select all

ls 'C:\yourfolder' | ? {($_.PSIsContainer)} | % {$_.fullName} | % { new-item -path "$_\MFGPLAN" -type directory}
Last edited by jumper (15 Mar 2010 12:36)

----------------------------

#10 15 Mar 2010 13:31
David W. Weekley


Thanks for the assist gentlemen. This worked great. I am going to have to spend more time with this.

David
Post Reply