• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Search & replace link strings in HTML using VB6 and fso

I have a directory full of .HTML files that have been renamed.  I have already used fso to read from one directory and according to data in a SQL database copy the file to another directory with no problem.  Now I need some help in pasing the files in the destination directory and replacing part of a link definition.

ie:
        File name is 2000371WFM_A.html

        Contains 1 or more links that are coded as "Data/20005212040B.html"

        Need to replace with "2000371WFM_B.html"
0
Jeff_Kingston
Asked:
Jeff_Kingston
1 Solution
 
gecko_au2003Commented:
From your example how exactly do you intend on replacing the link defintion ? Are you going to take the file name "2000371WFM_A.html" and the coded link ""Data/20005212040B.html" to ascertain this "2000371WFM_B.html"

ie you take the first 11 chars of the file name ie "2000371WFM_" and store that in one variable ( whether it is an array that is used to store different file names or just one variable ) then truncate the "Data/" and the next 11 digits off of the link(s) that are coded to leave you with B.html ( hence you can just use the left function to get the letter B)

then from there you can concatenate the variable ( which holds the first part of the file name ) with the letter B and also concatenate that with the file type ( which in this example is .html)

Is that what you are trying to get out of this as an answer or am I looking at this wrong ?
0
 
vinnyd79Commented:
Dim fso, MyFile, Filedata
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("2000371WFM_A.html")
Filedata = MyFile.ReadAll
MyFile.Close

Filedata = Replace(Filedata, "Data/20005212040B.html", "2000371WFM_B.html")

Set MyFile = fso.OpenTextFile("2000371WFM_A.html", 2, True)
MyFile.Write Filedata
MyFile.Close
0
 
gbzhhuCommented:
Open the file and assign the content of the html file to a string HTML_Str
   
    Dim s2 As String
       
    s2 = Replace(HTML_Str, "Data/20005212040B.html", "2000371WFM_B.html", , , vbTextCompare)

This will replace all Data/20005212040B.html with 2000371WFM_B.html and it will return s2 containing the new HTML with the changes

The trouble will be that it is always going to be Data/20005212040B.html

One workaround to that will be to read the file a line at a time with fso then use instr function to determine if the line contains the string "Data/" when you find it then use Right function starting from the position the Instr function returned up to length of 22 (which the length of your file name to replace)  This will give you the file name then use the replace function as above fiving the file name in the second parameter

Need more help with this let me know

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now