Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help: replacing text in multiple text files in a single directory.

Status
Not open for further replies.

TheAtomic

Technical User
Oct 18, 2004
9
GB
I'll go from the start give you a full understanding.

Basically I have a bunch of files (peoples names eg smithj, jonesp, carterg etc.) and I needed it to create a folder with the same name and move the file to it.

eg. smithj.htm -> smithj/smithj.htm

Im using this to do that:

Const strFolderPath = "C:\testfiles"
Dim fso, objFolder, strFileLessExt

Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(strFolderPath)

For each objFile in objFolder.Files
strFileLessExt = Left(objFile.Name, InStr(objFile.Name, ".") - 1)
If Not fso.FolderExists(strFolderPath & "\" & strFileLessExt) then
fso.CreateFolder(strFolderPath & "\" & strFileLessExt)
End If
objFile.Copy(strFolderPath & "\" & strFileLessExt & "\")
Next

set fso = Nothing
set objFolder = Nothing


That wasnt too bad to make...

The files are HTML files, and there is an image in them, named the same as the file.

I need the script to search the file and replace that string before it copies it into the new folder created in the above example.

eg. in smithj.htm is <img src="images/smithj.jpg"> this should be replaced with <img src="photo.jpg">

I know you need to read the file into a string search that then replce it but it a little above my knowledge.
 
Take a look at the Replace function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top