Text files as input to batch command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rabbit123
Posts: 2
Joined: 12 Jan 2009 01:33

Text files as input to batch command

#1 Post by rabbit123 » 12 Jan 2009 01:37

Hi everyone!

I would like to ask how can I create a batch file that inputs data from a text file? Say, I create a batch file with the command "del", and I want it to delete all the files listed in a text file.

My Text file:
1.jpg
2.jpg
3.jpg

How can I make the batch file delete all these files?

I know you can do it this way:
@echo off
set /p Test=<text.txt
del %Test%

However, how do I do it for multiple lines in a text file?

Thank you!

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2009 01:41

rabbit123,

Use FOR loop:

Code: Select all

@echo off
for /f "tokens=*" %%A in (text.txt) do ECHO del %%A

Note, the "ECHO" is for testing.

DosItHelp? :wink:

rabbit123
Posts: 2
Joined: 12 Jan 2009 01:33

#3 Post by rabbit123 » 17 Jan 2009 04:09

Hi DosItHelp!

Thanks for the reply. However, I was looking for more complex and multiple commands, and I found the answer already. By deleting the first line after each set of commands is carried out, what I wanted could be done. Thanks anyways!

songkok
Posts: 3
Joined: 03 Feb 2009 14:04
Location: Germany

#4 Post by songkok » 03 Feb 2009 14:21

could you post your batch codes here. i want to learn more about this.

thanks!!! :wink:

Post Reply