I had asked a question about parsing a file in ruby. I accepted an answer and wrote the following ruby script:
file = File.open('X:myfile.txt', 'r')
file.each_line do |line|
ccyy = line[53...57]
mmdd = line[57...61]
line[53...57] = mmdd
line[57...61] = ccyy
File.open('c:\myfile_MODIFIED.txt', 'a') do |f2|
f2.puts line
end
end
This script will run in production and change the file, however, production is a windows box and only vbscript is allowed to run on it. Unfortunatley I havn't written anything in VB before. Can someone help in converting the meat of above code to vb?
What I have so far is:
Dim oFolder, oFile, sText, ots
Set OFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = OFSO.GetFolder("X:\myfolder")
Set RegXP=New RegExp
RegXP.IgnoreCase=1
RegXP.Pattern="PROD_FILE_\d+.txt"
For Each oFile in oFolder.Files
If (RegXP.test(oFile.Name)) Then
WScript.Echo oFile.Name
set ots = OFSO.opentextfile(oFile)
Do While Not ots.AtEndOfStream
sText = ots.ReadLine
'read file line by line. change characters in the line. write line to new file'
Loop
ots.close
End If
Next