

InterviewSolution
Saved Bookmarks
1. |
Solve : creating multiple instances of folders in a directory? |
Answer» <html><body><p>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 <a href="https://interviewquestions.tuteehub.com/tag/every-243531" style="font-weight:bold;" target="_blank" title="Click to know more about EVERY">EVERY</a> 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<br/>Check the For /D option, it iterates through all directoriesperhaps I should have given an example, so try this<br/> Code: <a>[Select]</a>for /D %a in (*.*) do md "%%a\new folder" Quote from: gpl on <a href="https://interviewquestions.tuteehub.com/tag/july-244157" style="font-weight:bold;" target="_blank" title="Click to know more about JULY">JULY</a> 13, 2010, 01:35:40 PM</p><blockquote>perhaps I should have given an example, so try this<br/> Code: <a>[Select]</a>for /D %a in (*.*) do md "%%a\new folder"</blockquote> <br/>Sorry for my ignorance, but I'm relatively inexperienced with the command prompt. That being said, I <a href="https://interviewquestions.tuteehub.com/tag/read-619994" style="font-weight:bold;" target="_blank" title="Click to know more about READ">READ</a> 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:<br/><br/>│ ├───NE300<br/>│ │ └───AY11-1<br/>│ │ ├───<a href="https://interviewquestions.tuteehub.com/tag/additional-367648" style="font-weight:bold;" target="_blank" title="Click to know more about ADDITIONAL">ADDITIONAL</a> Resources<br/>│ │ ├───Admin Files<br/>│ │ ├───Homework Files<br/>│ │ ├───Instructor Files<br/>│ │ ├───Lab Files<br/>│ │ ├───Lesson Files<br/>│ │ ├───Submissions<br/>│ │ └───Writs and WPRs<br/><br/>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.<br/>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.<br/><br/>Suppose your master directory is called courses, inside are all of the course folders<br/>NE300<br/>NE310<br/>NE320<br/>NE340<br/>etc<br/><br/>and within each course there is an AY11-1 folder and inside that there is an Instructor Files directory<br/>This is quite easy, make Courses the current directory and execute the following to make JSmith in each<br/> Code: <a>[Select]</a>for /D %a in (*.*) do md "%%a\AY11-1\Instructor Files\JSmith"<br/>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<br/>Courses<br/>¦ +---NE300<br/>¦ ¦ +---AY11-1<br/>¦ ¦ +---Additional Resources<br/>¦ ¦ +---Admin Files<br/>¦ ¦ +---Homework Files<br/>¦ ¦ +---Instructor Files<br/>¦ ¦ +---Lab Files<br/>¦ ¦ +---Lesson Files<br/>¦ ¦ +---Submissions<br/>¦ ¦ +---Writs and WPRs<br/>¦ +---NE310<br/>¦ ¦ +---AY11-2<br/>¦ ¦ +---Additional Resources<br/>¦ ¦ +---Admin Files<br/>¦ ¦ +---Homework Files<br/>¦ ¦ +---Instructor Files<br/>¦ ¦ +---Lab Files<br/>¦ ¦ +---Lesson Files<br/>¦ ¦ +---Submissions<br/>¦ ¦ +---Writs and WPRs<br/>¦ +---NE320<br/>¦ ¦ +---AY11-3<br/>¦ ¦ +---Additional Resources<br/>¦ ¦ +---Admin Files<br/>¦ ¦ +---Homework Files<br/>¦ ¦ +---Instructor Files<br/>¦ ¦ +---Lab Files<br/>¦ ¦ +---Lesson Files<br/>¦ ¦ +---Submissions<br/>¦ ¦ +---Writs and WPRs<br/>¦ +---NE330<br/>¦ ¦ +---AY11-4<br/>¦ ¦ +---Additional Resources<br/>¦ ¦ +---Admin Files<br/>¦ ¦ +---Homework Files<br/>¦ ¦ +---Instructor Files<br/>¦ ¦ +---Lab Files<br/>¦ ¦ +---Lesson Files<br/>¦ ¦ +---Submissions<br/>¦ ¦ +---Writs and WPRs<br/><br/><br/>then a nested loop will be needed to identify the relevant <a href="https://interviewquestions.tuteehub.com/tag/path-11833" style="font-weight:bold;" target="_blank" title="Click to know more about PATH">PATH</a> 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 !<br/><br/> Code: <a>[Select]</a>for /D %%a in (*.*) do Call :ProcFolder "%%a"<br/>GoTo :EOF<br/>:ProcFolder<br/>for /D %%b in ("%1\*.*") do md "%%b\Instructor Files\JSmith"<br/></body></html> | |