Page 1 of 1

Text files as input to batch command

Posted: 12 Jan 2009 01:37
by rabbit123
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!

Posted: 16 Jan 2009 01:41
by DosItHelp
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:

Posted: 17 Jan 2009 04:09
by rabbit123
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!

Posted: 03 Feb 2009 14:21
by songkok
could you post your batch codes here. i want to learn more about this.

thanks!!! :wink: