1.

Solve : [solved] Batch processing text files?

Answer»

Hello,

I'm trying process text files from directory, but i do something in wrong way.

Code: [Select]@echo off
for %%i IN ('D:\txts\*.txt') do
java -jar D:\java\somefile.jar -i < %%i > %i_done.txt
It should look like this:
Code: [Select]java -jar D:\java\somefile.jar -i inputfile.txt > output_done_file.txt
But, of course it doesn't work it that way. What i do wrong?
You missed out the opening and closing parentheses and you may need to escape the < and > symbols. And I don't know what this

Code: [Select]%i_done.txt
is meant to be

%i_done.txt
is suppose to make
the original name PLUS _done.txt
so
hello_world.txt
would become hello_world.txt_done.txtQuote from: smeezekitty on August 20, 2009, 02:29:31 PM

%i_done.txt
is suppose to make
the original name plus _done.txt
so
hello_world.txt
would become hello_world.txt_done.txt

Why has it only got one % SIGN?
that would be an errorQuote from: smeezekitty on August 20, 2009, 03:34:10 PM
that would be an error

Quote
What i do wrong?

There may be othersI try to achieve such goal:

Take all text files from input directory and let some java program do it's work.
But this program must have defined in and out.
It works fine with commands:
Code: [Select]java -jar somefile.jar -i C:\input_dir\file1.txt -o C:\output_dir\file_done.txt
java -jar somefile.jar -i C:\input_dir\file1.txt > C:\output_dir\file_done.txtI cannot do:
Code: [Select]java -jar somefile.jar -i C:\input_dir\*.txtbecause output is not specified or produces 0 byte output for *.txt which for me it's useless. I need put processed files into different directory with maybe changed names.
Does the closing parenthesis MEANS:
Code: [Select](java -jar D:\java\somefile.jar -i %%i -o %%i_done.txt) I guess not...did it work or not?
i am confused Well, the only thing that works is command in cmd:
Code: [Select]for %i in (c:\input\*.txt) do java -jar somefile.jar -i %i > %i_done.txtBut if it works in cmd i don't care how to write it in batch file - thanks for all replies.
Quote from: Lu on December 18, 1973, 10:18:07 AM
Well, the only thing that works is command in cmd:
Code: [Select]for %i in (c:\input\*.txt) do java -jar somefile.jar -i %i > %i_done.txtBut if it works in cmd i don't care how to write it in batch file - thanks for all replies.

Take your code, add
@echo off
on a line above it and paste it into notepad. Save it as myscript.bat and there you go!Quote
paste it into notepad. Save it as myscript.bat

Don't forget to change %i to %%i


Discussion

No Comment Found