String Replacement (Find & Replace in .htm Files)
$30-250 USD
Completed
Posted about 15 years ago
$30-250 USD
Paid on delivery
Str-replace program (Design Spec is in Word Document in .zip file which is easier to read). Should be fairly straight forward project.
Very similar to the string replace that I had programmed by a 3rd party vendor a few months ago.
Program Execution:
str-replace [location of the htm files] [replace_string_file] [?]
where
[location of the htm files] - is the location of all the htm files that need string replacement
[replace_string_file] - is the name of the file that has the strings to be replaced
In the same directory of the [login to view URL] is a parameters file (parms)
The parms file contain portions of the static string replacement as well as error conditions and files to not do any string replacement:
FIND_TXT = "[login to view URL]' + indexURLparam + '" title="view thumbnails"> <- note all characters need replacing including the "
REPLACE_TXT = [login to view URL];ssPageName=STRK:MESELX:IT&item=
SUFFIX = “>
ERROR_TXT = [login to view URL] || NULL <- This can be NULL (checked for in the program)
IGNORE_FILES = [login to view URL], [login to view URL], thumbnailes2_template
How the program will work:
Below is the replace_string_file called [login to view URL]
[replace_string_file] [login to view URL]
220383175068,9323-301 ($7.95) DRM-COPY 35mm NEG
220383175269,9323-302 ($7.95) DRM-COPY 35mm NEG
220383175435,9323-303 ($7.95) DRM-COPY 35mm NEG
220383175636,9323-304 ($7.95) DRM-COPY 35mm NEG
220383175889,9323-305 ($7.95) DRM-COPY 35mm NEG
220383176135,9323-306 ($7.95) DRM-COPY 35mm NEG
[location of the htm files] is the location of all the htm files to be searched and have strings replaced (in this example it's: f:\2009\mar\9327\800\HTML)
f:\2009\mar\9327\800\HTML
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
[login to view URL]
Executing the program:
If the following is typed:
str-replace
PROMPTS THE FOLLOWING: Where is the location of the html files?
f:\2009\mar\9327\800\HTML
PROMPTS THE FOLLOWING: Name of the replace string file?
e:\mywebsites\ebay\[login to view URL]
OR THE FOLLOWING CAN BE TYPED
str-replace f:\2009\mar\9327\800\HTML e:\mywebsites\ebay\[login to view URL]
OR THE FOLLOWING CAN BE TYPED
str-replace /? <- which will just provide the parmeters of the program shown below:
str-replace [location of the htm files] [replace_string_file]
[/?]
What the program will do:
1) It will gather all of the .htm files from the directory [location of the htm files] - If no files exist, then an error log contains - no files found
2) The name of the htm file will be parsed up to the "." (for example, [login to view URL] will be 9323-301) and placed into a variable called Find
First check to see if the file is to be ignored (where no replace is done). These are in the parms file IGNORE_FILES (In this case [login to view URL], [login to view URL], and [login to view URL] are to be ignored)...If it is one of these files, then go to the next .htm file
3) Gathering the string replacement dynamic data
from the [replace_string_file], search for the VAR Find (in this case 9323-301) in the replace_string_file
it is found on line one:
220383175068,9323-301 ($7.95) DRM-COPY 35mm NEG
if it is not found (like the file named [login to view URL]) then generate a message in the erro log but still do the search on the file.
4) Grab the dynamic data VAR Dynamic_Replace is the begining data up to the comma (in this case Dynamic_Replace = 220383175068)
Error_Handling: if the Find string is not found (like the file named [login to view URL])
FIRST: Log an error in the error log: this-one-will-give-an-error was not found in the find/replace file
SECOND: Check the Parms Parameter ERROR_TXT is set to "NULL" , if it is then do not do a replace and just go to the next file. If it is NOT set to null, do the replace with the ERROR_TXT set in parms file
5) Do the find and replace in the .htm file
First search for the FIND_TXT (if it is not found then put in the error log FIND_TXT ,along with the text from the parms file, in the error log)
IF the FIND_TXT IS FOUND:
Second see if it is an error replace (remember, if the file wasn't found AND the ERROR_TXT was not null, the replace is ERROR_TXT) If it is an error_replace, the just replace the FIND_TXT with the ERROR_TXT
If it is NOT an error replace the FIND_TXT in the file with the REPLACE_TXT and at the end of the REPLACE_TXT place the Dynamic_Replace
For example: Find txt: "[login to view URL]' + indexURLparam + '" title="view thumbnails">
would be replaced with: [login to view URL];ssPageName=STRK:MESELX:IT&item=220383175068
Design Spec:
str-replace
VARS
Htm_Location // Location of the htm files
Replace_String_File // Location of the Replace string file
Html_Find // Data to search in the replace string file
Replace_String_Search_Error // Boolean if the Replace String is not found set to true
// Gather parameter data
If no parameters Then
Prompt "Where is the location of the .htm files?"
Htm_Location = Prompt response 1
Prompt "Where is the replace string file?
Replace_String_File = Prompt response 2
Else if parameter = "/?"
Prompt str-replace [location of the htm files] [replace_string_file] [/?]
Exit
Else
If num parameters = 2 Then
Htm_Location = first parmeter
Replace_String_File = second parameter
Else
Prompt str-replace [location of the htm files] [replace_string_file] [/?]
Exit
//Gather the find and replace - find replace //
LOOP While there are still .htm files
Replace_String_Search_Error = False // Set this to false as default
// Check to see if the file is to be ignored (from the parms file)
If Html_Find = IGNORE_FILES Then
Goto next .htm file
Else
// Parse the .htm file up to the "."
Html_Find = (the data up to the .)
SEARCH Find_Replace File (routine)
look for the Html_Find in the Replace_String_File
If Html_Find is found Then
Dynamic_Replace = The parsed file up to the comma // In this example if Html_Find = 9323-301, then the Dynamic Replace = 220383175068
// from the data above -> 220383175068,9323-301 ($7.95) DRM-COPY 35mm NEG
Else
If ERROR_TXT = "NULL" Then // If the ERROR_TXT in the parms file is null, then ignore the file
Goto to next .htm
Else // Otherwise replace the data in the Replace routine with the ERROR_TXT (by setting the
Replace_String_Search_Error = True // Boolean to true
REPLACE (routine)
look for the FIND_TXT in the .htm file // This should always be found, but if it isn't a log file is generated, this is incase
If FIND_TXT not found // My HTML code generator changes and I don't know why the program suddenly doesn't work
Append Error log with (FIND_TXT "[login to view URL]' + indexURLparam + '" title="view thumbnails"> not found)
Goto to next .htm file
Else
If Replace_String_Search_Error = False Then // Replace FIND_TXT with REPLACE_TXT & Dynamic_Replace replace the FIND_TXT with REPLACE_TXT & Dynamic replace & SUFFIX
(in the example above: "[login to view URL]' + indexURLparam + '" title="view thumbnails"> would be replaced with:
[login to view URL];ssPageName=STRK:MESELX:IT&item=220383175068">
Else
replace the FIND_TXT with ERROR_TXT
(in the example above: the file [login to view URL] will have the following text change
"[login to view URL]' + indexURLparam + '" title="view thumbnails"> would be replaced with:
[login to view URL]
Goto Next .htm file
END LOOP While there are still .htm files