Käynnissä

String Replacement (Find & Replace in .htm Files)

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 [url removed, login to view] 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 = "[url removed, login to view]' + indexURLparam + '" title="view thumbnails"> <- note all characters need replacing including the "

REPLACE_TXT = [url removed, login to view];ssPageName=STRK:MESELX:IT&item=

SUFFIX = “>

ERROR_TXT = [url removed, login to view] || NULL <- This can be NULL (checked for in the program)

IGNORE_FILES = [url removed, login to view], [url removed, login to view], thumbnailes2_template

How the program will work:

Below is the replace_string_file called [url removed, login to view]

[replace_string_file] [url removed, login to view]

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

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

[url removed, login to view]

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\[url removed, login to view]

OR THE FOLLOWING CAN BE TYPED

str-replace f:\2009\mar\9327\800\HTML e:\mywebsites\ebay\[url removed, login to view]

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, [url removed, login to view] 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 [url removed, login to view], [url removed, login to view], and [url removed, login to view] 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 [url removed, login to view]) 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 [url removed, login to view])

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: "[url removed, login to view]' + indexURLparam + '" title="view thumbnails">

would be replaced with: [url removed, login to view];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 "[url removed, login to view]' + 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: "[url removed, login to view]' + indexURLparam + '" title="view thumbnails"> would be replaced with:

[url removed, login to view];ssPageName=STRK:MESELX:IT&item=220383175068">

Else

replace the FIND_TXT with ERROR_TXT

(in the example above: the file [url removed, login to view] will have the following text change

"[url removed, login to view]' + indexURLparam + '" title="view thumbnails"> would be replaced with:

[url removed, login to view]

Goto Next .htm file

END LOOP While there are still .htm files

Taidot: C-ohjelmointi

Näytä lisää: find replace string program, program find replace string, replace htm, work find, what is search string, what is in, what is a search string, up string, to string, text to string, text string search, string the, string search in c, string i, string find c, string 2, set in c, search text string, search string in c, search string c, search string, search in code, search c string, program find, just the begining

About the Employer:
( 7 reviews ) Jupiter, United States

Projektin tunnus: #409281

Myönnetty käyttäjälle:

fstudio

Dear sir, I can do it for you, Could you see PMB for more details? Thanks. Best Regards.

80 $ USD 2 päivässä
(55 arvostelua)
5.6

2 freelanceria on tarjonnut keskimäärin 165 $ tähän työhön

J711

Hi, i could to do this.

250 $ USD 11 päivässä
(1 arvostelu)
2.5