0

I have a text file as follows:

file.txt

1. Adams Johnson - VB
2. Mike Robert - C++
3. victor -java
... and so on for almost 700 entries in that text file

I have to create folders with each line of this text file using a batch file.

I have tried the following code:

@echo off
for /f "tokens=*" %%a in (file.txt) do (

mkdir %%a

)

but my folders are created as follows:

1
2
3
... so on...
Adams 
Johnson
Mike 
Robert
Victor 
... so on...

I want it something like this:

1. Adams Johnson - VB
2. Mike Robert - C++
3. victor -java
... and so on.

How can I get that?

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
Krishna Chandra
  • 1
  • 1
  • 1
  • 1

1 Answers1

5
@echo off
for /f "tokens=*" %%a in (file.txt) do (

mkdir "%%a"

)

Space is a default separator, so mkdir (or md - they're equivalent) thinks you want this one and that one and the other one.

Actually, I'd prefer "delims=" over "tokens=*" but if it works for you...

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • +1 For the `"delims="` comment to get the entire line, as is the intent. `"tokens=*"` is similar, except it also trims leading spaces. – dbenham May 25 '13 at 14:11
  • @Nagarajan : I would not know how to start on a mac. You should create your own question - no doubt someone will respond. – Magoo Dec 27 '14 at 07:11