Solved

Creating directories from a list inside a text file

Posted on 2011-03-18
5
340 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 84

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 84

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 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