Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating directories from a list inside a text file

Posted on 2011-03-18
5
Medium Priority
?
355 Views
Last Modified: 2012-05-11
I have a text file with 100 lines.  

Each line has a single word on it.

How to I have mkdir read this file and create a folder for each word?

Example
     Text file
          Red
          Green
          Blue
         

I want MD to create a folder for every word in the text file.
0
Comment
Question by:MikeLyons74
5 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 35169091
Assuming the text file is in the same folder as the directories you want to create:

Directly from the command line:
for /f "delims=" %a in ('type "file.txt"') do md "%a"

In a script:
for /f "delims=" %%a in ('type "file.txt%"') do md "%%a"

Open in new window

0
 
LVL 85

Expert Comment

by:oBdA
ID: 35169099
Oh, just in case: the "script" version below refers to a batch (whatever.cmd) script, not VB.
0
 
LVL 39

Expert Comment

by:BillDL
ID: 35172175
Hi Mike

I notice that you have shown the text in a kind of "nested" layout:

Example
     Text file
          Red
          Green
          Blue

Just to clarify something.  Are all the "words" in the file up against the left margin when opened in Notepad, or is there some kind of "sub-folder" hierarchy needed here?

You just want to create folders named "Red", "Green" and Blue", right?
Is the "Text File" line actually part of the text file, eg. a heading in it from which you want to create a master folder and then sub-folders in that for the indented text below it?

Bill
0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 35172750
If you don't like playing with Scripts just import the list into a spreadsheet into column B

Then add "MD <Drive:Path/> "   to the Column a  and copy it down
where <Drive:path>  is the approriate drive and initial path (never do it on c:\ or for that matter any other actual drive - in the root - that can really mess you up - there are restrictions on how many actual folders are allowed in the root directories - Also if it messes up you just delete the master folder

If there are in fact nested folders - the primary folder needs to be created on a separate command line - then create the subfolder

0
 

Author Closing Comment

by:MikeLyons74
ID: 35182817
Thanks, this is exactly what I needed.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question