HTML files are text files, so you can read them in the same way you would read any other text files (for example, using the FileSystemObject
object).
Now, is there a way for my script to open all .html files in a specified folder without knowing their names?
You can enumerate the Folder.Files
collection and check the file extension, like this:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim oFSO, oFolder, oFile, oTextStream, strText
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:MyFolder")
For Each oFile In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "html" Then
Set oTextStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault)
strText = oTextStream.ReadAll
oTextStream.Close
Do something with strText
Set oTextStream = oFile.OpenAsTextStream(ForWriting, TristateUseDefault)
oTextStream.Write strText
oTextStream.Close
End If
Next