Solved

Creating directories from a list inside a text file

Posted on 2011-03-18
5
305 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 83

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 83

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now