views:

156

answers:

3

Here's the situation:

I have a lot of HTML files, and these HTML files link to a lot of documents. The documents have ALL been renamed. I have an excel sheet which has the old name of the file and the new name of the file.

What would be the quickest way to change the links inside the HTML files to accommodate the new names?

The method I'm using now: Have all the HTML files opened in Notepad++ Use Notepad++'s 'Replace in All Opened Documents' function to replace all occurrences of a certain link with the new file name.

Is there a quicker, better way?

+1  A: 

Perl's regular expressions.

elaboration: pseudocode

open up each file for read-only and read them into a list.
close the files
foreach element in the list
#do the desired text replacement
`s/$oldtext/$newtext/g`;
open each file once more now for writing
write out the new text.

It's not hard, but requires some testing. If you have a lot of edits(and more may happen later), this is more efficient.

Paul Nathan
Care to elaborate? :)
Nikko
This worked. I used PHP though instead of Perl, and regular expressions weren't really needed.
Nikko
+1 for regexp:s (regardless if used from perl or php)
Johan
A: 

There are several free and open-source tools that replace text in several files, one of the open-source ones is FART

If you prefer something with a GUI, try the free Text Crawler

Diaa Sami
Would these solutions require installations? As I'm doing this for work, installing something on my PC would be out of the question.
Nikko
@Nikko: FART doesn't require installation, it's just an executable.
Diaa Sami
A: 

First save the excel to somethine nice and simple like a csv file so its easy to read in you favourite language eg perl. Iterate over each file and do the search and replace. One gotcha though is to do it all in one pass otherwise you could create problems if there are links that have changed in complex ways. Ie if file a.html changed to b.html and b.html changed to a.html you can mess up the links if you do it in multiple passes. So load all the changes into memory then cycle through each file and replace all links in it simultaneously.

Because it is specifically html search and replace a tool like this would be ideal:

http://www.aliassoftware.com/

Finds and Replaces multiple text strings in multiple files at once !

Brendan Heywood