I have attached the following code contained in a vbs file that I use to parse a file.
I would like to modify this code so that it will process every file in the folder.
Each file has the same prefix "h837.2010".
Thanks
Dim sCurPath
CurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Const ForReading = 1
Const ForWriting = 2
strFolderName = CurPath
strTargetFile = CurPath & "\837a.txt"
strFileNameConstant = "h837.2010"
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSubfolders = objWMIService.ExecQuery ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " & "ResultRole = PartComponent")
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile where Path = '" & strPath & "'")
For Each objFile in colFiles
If InStr(Lcase(objFile.Name),LCase(strFileNameConstant)) Then
Set objFile = objFSO.OpenTextFile(objFile.Name, 1)
strSearchString = objFile.ReadAll
objFile.Close
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "BHT"
strNewText = objRegEx.Replace(strSearchString,VBCrlf & "BHT" & VBCrLf)
End If
Next
'Writes Target file
Set objFile = objFSO.OpenTextFile(strTargetFile, ForWriting, true)
objFile.WriteLine(strNewText)
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("837a.txt", 1)
strSearchString = objFile.ReadAll
objFile.Close
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "~"
strNewText = objRegEx.Replace(strSearchString, VBCrLf)
Set objOUtFile = objFSO.CreateTextFile("837b.txt", 2)
objOutFile.WriteLine strNewText
objOutFile.Close
Select all Open in new window
I will however post another question tomorrow as soon as I get the batch code written that will attempt to take the parsed results and transpose the data from line to column.
Thanks for your help Bill