Click here to Skip to main content
14,700,123 members
Articles » Web Development » Applications & Tools » Tools with source code
Article
Posted 22 Mar 2004

Stats

40.1K views
21 bookmarked

WinTextFilePatch

Rate me:
Please Sign up or sign in to vote.
3.27/5 (7 votes)
24 Mar 2004Zlib
A super search and replace tool

Image 1

Introduction

Many times, I was involved in sorting my Opera (fantastic web browser, for whose don't knot it) cache, keeping in a safe place some HTML file, deleting some other useless. In the kept files, I often had to search for URL and retrieve the file associated. It was a huge task, even if Opera can nicely manage download. So I create HTML files with all the URL, then use a web grabber to retrieve them in background.

But the task to compile all files, look for all the URL, creating a single HTML still have to be done by hand. So I created this little tool to look for a specific pattern in a set of files and output multiple or an unique file with the URL. It was then too much easy to compile stuffs ;)

Features

The tool allows to fetch only the wanted part of text, to input the text one or multiple times in another text, include the unmatched text and so on, so you may do almost everything with this tool ;)

Using the tool

Imagine in a HTML file you have, between the mess and the ads, such links :
<span class="imagelink">
http://galleries.amberlace.com/ndnikki1/pics/01.jpg:
<br /><img src="http://galleries.amberlace.com/ndnikki1/pics/01.jpg">
<br clear=all><BR><BR><BR>

<span class="imagelink">
http://galleries.amberlace.com/ndnikki1/pics/02.jpg:
<br /><img src="http://galleries.amberlace.com/ndnikki1/pics/02.jpg">
<br clear=all><BR><BR><BR>

<span class="imagelink">
http://galleries.amberlace.com/ndnikki1/pics/03.jpg:
<br /><img src="http://galleries.amberlace.com/ndnikki1/pics/03.jpg">
<br clear=all><BR><BR><BR>

<span class="imagelink">
http://galleries.amberlace.com/ndnikki1/pics/04.jpg:
<br /><img src="http://galleries.amberlace.com/ndnikki1/pics/04.jpg">
<br clear=all><BR><BR><BR>
...

Now you wants to save them cleanely in the same file without the mess and the ads, or compile every URL you may find in a big file, in order to get this :

<a href="http://galleries.amberlace.com/ndnikki4/pics/1.jpg">
http://galleries.amberlace.com/ndnikki1/pics/1.jpg</a><br>

<a href="http://galleries.amberlace.com/ndnikki1/pics/2.jpg">
http://galleries.amberlace.com/ndnikki1/pics/2.jpg</a><br>

<a href="http://galleries.amberlace.com/ndnikki1/pics/3.jpg">
http://galleries.amberlace.com/ndnikki1/pics/3.jpg</a><br>

<a href="http://galleries.amberlace.com/ndnikki1/pics/4.jpg">
http://galleries.amberlace.com/ndnikki1/pics/4.jpg</a><br>
...
Here the explanation step-by-step, section-per-section :

File

Source : Source folder that contains the files. Currently no sub-directory support.

Extension : File extension to process, separated with a semi-column. If empty, process every file of the source folder.

Destination : Destination folder, where the modified files have to be written. If the path ends with a filename, things extracted will be written inside a unique file.

Text

Here comes the most interresting part, but be cautious :

Start : The beginning of the text to look for. In the previous example/pattern, it would be

<span class="imagelink">

Body : Name the body part you wan to keep safe and write in the destination file. Leave it to body if you want, it's not such important...

End : The end of the text that will encapsulate the body. From the previous example, it would be after the interresting URL, such

:<br /><img src=

Replace : Put here the replacement line including the retrieved body. To include the body, just write the body name with a percent sign before. Hence, to create a valid URL, write

<a href=\"%body\">%body</a><br>

Include unprocessed text : Include in the output file the text found before the start and after the end of what have to be processed. Hence you may just modify/clean a file ;)

Add end of line : Add an end-of-line after each match. Useful to create one line per URL.

Encapsulation

Header : Header of the new file.

Tail : Tail of the new file.

Process

!!! : Let's GO !

History

None yet ;)

Disclaimer

  • First the tool IS NOT Unicode compliant. It just process single byte charset.
  • Second, sorry for the morons who will be shocked by the links I gave as example. It's just cute ;)
  • Third, this is provided as is. I'll make upgrades on purpose. But feel free to modify the tool for your own usage.
  • Fourth, this tool is far more useful than you even expected. It lacks also of a configuration saving, in order to set back a parameter set to process another bunch of files.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License

Share

About the Author

Kochise
Software Developer
France France
KOCH David, 41 years old
Coder (embedded, C/C++, ASM, Erlang)

Comments and Discussions

 
Generala great inexpensive tool that does this Pin
jrocnuck9-Jan-05 12:04
Memberjrocnuck9-Jan-05 12:04 
GeneralHmmm... Pin
Kochise15-Jan-05 11:50
MemberKochise15-Jan-05 11:50 
QuestionRegular Expressions??? Pin
Gilad Novik22-Mar-04 22:37
MemberGilad Novik22-Mar-04 22:37 
AnswerYep, I now, I just needed something fast... Pin
Kochise22-Mar-04 23:33
MemberKochise22-Mar-04 23:33 
...and the opportunity to make fun of it Wink | ;) Look at the code !

I know a little about regexp, I would have used Notepad RE (often updated on CodeProject), but for various purposes, I needed a single GUI project which allows me to compile the files I needed Wink | ;)

But thanks for the tip for people having some interrest in the subject Smile | :)

Kochise

In Code we trust !

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.