Solved

Creating directories from a list inside a text file

Posted on 2011-03-18
5
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 250 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 38

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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

615 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