0

I' would like to read student names from a textfile (student.txt) and create a directory for each student.

I used this command:

for /f "tokens=1* delims=" %%i in (student.txt) do ( md %%i )

But when I run it and the student name is Jay Leno for example. It makes two directory's. One Jay and one Leno. I want only one directory, "Jay Leno"

Any help would be greatly appreciated. I'm new to this :)

1 Answer 1

1
for /f "delims=" %%i in (student.txt) do ( md "%%i" >nul 2>nul)

The directory to be created needs to be in "quotes" if it contains spaces (optionally if it doesn't)

The 2>nul suppresses error mesages if the directory already exists

The >nul suppresses the 'created' report.

(either or both of which can be omitted at your option)

3
  • Thank you! Now I would like to have the batch file make a directory group1 for example and have the directory's of the students made in the group1 directory. I thought this would be easy... Can't seem to figure it out
    – Tommy
    Jan 7, 2014 at 14:23
  • You'd need to create a new question - they don't cost very much - and specify how the batch is supposed to tell to which group a student belongs so the directory group\student can be created.
    – Magoo
    Jan 7, 2014 at 14:33
  • Figured it out myself. Thank you for your help!
    – Tommy
    Jan 7, 2014 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.