A real life example

Examples

How to replace a string by another in a series of files...

I had started to do those examples on my laptop and then moved them to my usual workstation.
The two computers have different IP addresses and that affected the <FORM action="..."> tag in some of my examples.
After considering different options, (Manual replacement,C, PERL...) I found that Aptilis was actually the most indicated solution.
(No, really that's how it happened!)

sub main

	// That's the IP of my laptop
	origin = "10.0.0.44" $

	// and the one my desktop uses
	new = "192.168.2.4" $

	// Just get all the files we want
	n = getFileList(fl[], "*.html")

	for i=0 to n-1

		// We have a file name in fl[i]
		print(fl[i]$,"\n")

		// Now, we just load the file into f$
		f = loadfile(fl[i]$) $

		// If you wanted to, you could keep a backup.
		// savefile(fl[i] + ".bak" $, f$)

		// Here we replace the bit we want to replace
		f = replace(f$, origin$, new$) $

		// ...and we put the file back on the disk.
		savefile(fl[i]$, f$)

	end for

end main