Solved

Creating directories from a list inside a text file

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove header from multiple csv files using batch script 11 81
Help me. 3 54
VB6 ListBox Question 4 44
Problem to With line 4 57
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

770 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