I have a large folder of word 2003 files (200+). I need a way to make sure that every file ends with the exact same characters. Some of these files already end with this characters so I cannot duplicate the ending.

What I need is that every file, after it's last character, usually a "." but not always, I need to have two carriage returns, and nothing else. Emphasis is here is the 2 returns, no more than that.

Recommended Answers

All 3 Replies

The way I would do it is to create a vbscript file that creates a Microsoft Word object and uses that in a loop to open each file in the folder and check the text. If you are not familiar with scripting or creating scripted controls then it becomes very difficult. I had to create many such scripts to tie processes together before I retired.

Yes I do, quite a bit actually. I managed to solve my own issue by creating a C# winforms app that used the Microsoft.Office.Interop.Word namespace. I simply looped through all the text backwards till I found a character that wasn't a space or a new line. Deleted everything after that point, the added the correct number of new line characters at the end. As far as looping through the file system, LINQ made that easy to sort out only the .doc files.

Side note, I think I had a seizure watching Word flash across my screen that quickly.
7 min total for 768 files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.