1.

Solve : creating multiple instances of folders in a directory?

Answer»

I am tasked with reorganizing an academic server.  I have recently realized that there needs to be another folder in each of the course folders.  I don't want to go into EVERY single course folder and create a new folder using the regular windows explorer windows.  is there a way to do this repetetive task in the command prompt?  Thanks.yes, check out the FOR command - for /? will give help
Check the For /D option, it iterates through all directoriesperhaps I should have given an example, so try this
Code: [Select]for /D %a in (*.*) do md "%%a\new folder" Quote from: gpl on JULY 13, 2010, 01:35:40 PM

perhaps I should have given an example, so try this
Code: [Select]for /D %a in (*.*) do md "%%a\new folder"

Sorry for my ignorance, but I'm relatively inexperienced with the command prompt.  That being said, I READ the description of FOR /D and your example of code looks like the (*.*) is telling it to search in a set of files.  Let me give you an example directory:

│   ├───NE300
│   │   └───AY11-1
│   │       ├───ADDITIONAL Resources
│   │       ├───Admin Files
│   │       ├───Homework Files
│   │       ├───Instructor Files
│   │       ├───Lab Files
│   │       ├───Lesson Files
│   │       ├───Submissions
│   │       └───Writs and WPRs

There are about 40 more of these course directories (NE300 is a course) and I want to add a folder called JSmith in all of the existing "Instructor Files" folders.  Please let me know where I am making my mistake in understanding the code you gave me.  Thanks.
No, you are right - sort of. Directories can be treated as files, in as much as they have a name that can be filtered by *.*, or whatever.

Suppose your master directory is called courses, inside are all of the course folders
NE300
NE310
NE320
NE340
etc

and within each course there is an AY11-1 folder and inside that there is an Instructor Files directory
This is quite easy, make Courses the current directory and execute the following to make JSmith in each
Code: [Select]for /D %a in (*.*) do md "%%a\AY11-1\Instructor Files\JSmith"
However, I suspect that the actual name of the AY11-1 directory is different in each course; if it is the top level (ie the only one as you seem to indicate in your tree) within the individual course directory - like this
Courses
¦   +---NE300
¦   ¦   +---AY11-1
¦   ¦       +---Additional Resources
¦   ¦       +---Admin Files
¦   ¦       +---Homework Files
¦   ¦       +---Instructor Files
¦   ¦       +---Lab Files
¦   ¦       +---Lesson Files
¦   ¦       +---Submissions
¦   ¦       +---Writs and WPRs
¦   +---NE310
¦   ¦   +---AY11-2
¦   ¦       +---Additional Resources
¦   ¦       +---Admin Files
¦   ¦       +---Homework Files
¦   ¦       +---Instructor Files
¦   ¦       +---Lab Files
¦   ¦       +---Lesson Files
¦   ¦       +---Submissions
¦   ¦       +---Writs and WPRs
¦   +---NE320
¦   ¦   +---AY11-3
¦   ¦       +---Additional Resources
¦   ¦       +---Admin Files
¦   ¦       +---Homework Files
¦   ¦       +---Instructor Files
¦   ¦       +---Lab Files
¦   ¦       +---Lesson Files
¦   ¦       +---Submissions
¦   ¦       +---Writs and WPRs
¦   +---NE330
¦   ¦   +---AY11-4
¦   ¦       +---Additional Resources
¦   ¦       +---Admin Files
¦   ¦       +---Homework Files
¦   ¦       +---Instructor Files
¦   ¦       +---Lab Files
¦   ¦       +---Lesson Files
¦   ¦       +---Submissions
¦   ¦       +---Writs and WPRs


then a nested loop will be needed to identify the relevant PATH to the Instructor Files. Im sure that one of my esteemed colleagues will be able to show a wonderful bracket example, here is my offering using a subroutine call -- blimey it seemed to work first time !

Code: [Select]for /D %%a in (*.*) do Call :ProcFolder "%%a"
GoTo :EOF
:ProcFolder
for /D %%b in ("%1\*.*") do md "%%b\Instructor Files\JSmith"


Discussion

No Comment Found