View Full Version: ReplaceThis textfile program

Zoids Evolution Forums > Computers and Technology > ReplaceThis textfile program



Title: ReplaceThis textfile program


HaTcH - June 20, 2005 07:16 PM (GMT)
Ok, I have wanted to make this program for quite some time and I finally did. I named it ReplaceThis and what it does is search 1 or more files or multiple directories containing files of a certain extension for specified text and automatically replaces all occurances of a with b.

Huh?

Its a program that does the WordPad 'Replace All' function on a much larger scale.
Now you can update entire websites of multiple text files with the click of one button.

http://www.bearcreekfire.com/zoids3d/downl...ReplaceThis.exe (44kb) is the link.
Screenshot: http://www.bearcreekfire.com/zoids3d/downl...replacethis.jpg

Now you might ask yourself why would HaTcH write such a wierd program? Well the answer is because at LU, my navigation bar is hard coded into EVERY html file. That means if I want to change it, I have to go through like 80 or so individual files and change it manually. With this program, all I do is fill in the search and replace fields and click begin and it does all the work of finding the said text.

Scottfab - June 20, 2005 09:09 PM (GMT)
nifty. i dont think I have a use for it, but nifty nonetheless.

Tilly - June 21, 2005 12:11 AM (GMT)
I have some older stuff that needs updating to have includes, which is what I normally use for that. Too bad it's on the other computer back in Wisconsin...this could be quite handy then.

HaTcH - June 21, 2005 01:39 AM (GMT)
Ok, well I updated the program just a tad...
1. Fixed a few crashes resulting from 0byte files.
2. Made the screen refresh instead of going white while working.
3. Made the labels update while the program is running.
4. Tweaked the recursive method a tad.
5. Fixed some spelling mistakes...well everyones human

Now I am confident enough to run this on the only LU copy I have to majorly update my site! </stupid fuzors link that does nothing on every page...>

Again, you can find this program at http://www.bearcreekfire.com/zoids3d/downloads/projects.html

Capitila - June 21, 2005 06:43 AM (GMT)
Cool, could come in very handy. It's still no replacement for SSI though.
How long did you spend on it?

HaTcH - June 21, 2005 03:19 PM (GMT)
Well the original method, runMode1 took about 3~4 hours (with distractions). Thats the method that opens the file, reads it in, searches, counts number of replacements to be made, then replaces, writes back and continues looping. The hardest thing to figure out was the recursive algorithm to scour all sub directories. J'ever goto command prompt and type in tree c:? It displays a complete list of all the files within folders on your drive by opening up the highest dir, comming back down, moving to the next folder, expanding it, moving back, moving back, moving to the next.. It was pretty fun, that took a few hours yesterday.

Here is the code for the recursive parser:
CODE

Function runMode2(ByVal intPos As Integer) As Integer
   'recursively check each directory for more directories.
       'if no more directories are found, return the position + 1
       
'loop to count how many child directories exist within the current directory
   'ie, check to see if dir1.list(i) is nothing or not, if not add 1 to the count
   'this should be inside its own function
'for..loop to that number of how many times to call runMode1
'for i = 1 to <function value>
Dim i As Integer
Dim j As Integer
For i = 0 To children
   If Dir1.List(intPos + i) <> "" Then 'a higher dir exists
       'set the dirlist to the next higher directory
       Dir1.Path = Dir1.List(intPos + i)
       'Text1.Text = Text1.Text & vbCrLf & Dir1.Path '<-- will print a tree basically
       'select all files to comply with runMode1
       File1.Refresh
       For j = 0 To File1.ListCount - 1
           File1.Selected(j) = True
           'Text1.Text = Text1.Text & vbCrLf & vbTab & File1.List(j) 'ditto
       Next j
       Call runMode1
       Dir1.Path = Dir1.List(runMode2(intPos)) 'the recursive call
   End If
Next i
dirs = dirs + children
runMode2 = -2 'return -2 to goto parent directory after everything was searched
End Function


;p Debugging is what makes the program take so long. I mean I had the bulk of the code done after a short period, but I had to fix it all.

Momonga - June 22, 2005 08:53 AM (GMT)
Gah. So now you do it. *Has just been meddling with her site the long way* :P
Oh well, I stuffed it up anyway so I'll try this out on it! Thank you soo much!

HaTcH - June 22, 2005 08:54 PM (GMT)
OK, I did a little more tweaking...
1.) Made the interface more together
2.) Created a "side bar" kind of thing so you can see what files are modified and the path to them for easy identification.
3.) Minor code improvements (speed, system resources)

This program is really quite neat now.... I have this crap copy of LU on my other hard drive which I run this program through.. something like changing all <html> to <jtml> and then back again just to watch it work.




Hosted for free by InvisionFree