So I want to make a .vbs that edits all .txt in a folder. This the code I used, and the folder is C:\test folder
.
Const ForReading = 1
Const ForWriting = 2
newline = ""
line = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\test folder\"
Dim lineCount : lineCount = 0
Dim firstContent : firstContent = ""
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If LCase(objFSO.GetExtensionName(objFile)) = "txt" Then
lineCount = 0
firstContent = ""
FileName = objStartFolder & objFile.Name
Set objStream = objFSO.OpenTextFile(FileName, ForReading)
Do Until objStream.AtEndOfStream
lineCount = lineCount + 1
firstContent = firstContent & objStream.ReadLine & vbCrLf
If lineCount = line Then
firstContent = firstContent & newline & vbCrLf
End If
Loop
Set objStream = objFSO.OpenTextFile(FileName, ForWriting)
objStream.WriteLine firstContent
objStream.Close
End If
Next
It works. and changes all the text files to what I want them to say, but when I made a folder in C:\test folder
called SF
(C:\test folder\SF
), all of the text files in SF
don't change. How do I get it to work with subfolders?