Page 1 of 1

Batch Script to format 30,000 text files in multiple folders

Posted: 27 Jul 2011 04:52
by brisjast
Hello

Hoping someone will be able to assist

I have 30,000 .txt files split across 200 or so subfolders all contained within a main folder.

Is there a way to automatically read each file and strip out all linebreaks and carriage returns via a DOS batch script?

I am having trouble importing these files into another piece of software because of the linebreaks and cant face manually editing 30000 files!

Thank you in advance for assistance :wink:

Re: Batch Script to format 30,000 text files in multiple fol

Posted: 28 Jul 2011 03:36
by renzlo

Re: Batch Script to format 30,000 text files in multiple fol

Posted: 28 Jul 2011 06:13
by dbenham
I don't think the post renzlo suggested will help - It removes empty lines. It does not strip all <end of line> characters.

@brisjast - Are you sure your stated requirement is precise :?:

If you simply strip all <end of line> characters, then:
This
little
file
is
readable.

What
to
do
with
blank
lines?

Becomes unreadable
Thislittlefileisreadable.Whattodowithblanklines?


I suspect you want to preserve empty lines and for the rest you want to replace each <end of line> with a <space>:
This little file is readable.

What to do with blank lines?


The pure batch solution is not too difficult, but it will be slow for 30000 files. It would be better if you could locate a good text editor that allows search and replace of <end of line> that is also scriptable. If you find one that can do the search and replace but isn't scriptable, you can automate the process with AutoIT.

Better yet would be a text processing utility like perl or sed. Both are available for Windows for free.

Reply if you still want a pure batch solution, along with clarified requirements. It might be a few days before I have time to develop a solution. Someone else might beat me to it.

Dave Benham