ShopMonkey
Technical User
I'm working with some VERY large ascii lpd data files and it turns out there are some non-printing character sequences that are causing problems for my print management software. I need to do some heavy search and replace functions on the data for it to work properly.
I found a website with some variations on reading large files ( ) and the technet "Scripting Guy" article on searching and replacing text in a file ( )
Since the files I'm working with can be extremely large (80mb+ ) I chose to use the "read byte" method I found on the first reference site and the following is the code I came up with after combining the two:
const ForReading = 1
Const ForWriting = 2
const TristateFalse = 0
dim strDataCapture
dim objFS
dim objFile
dim objTS
set objFS = CreateObject("Scripting.FileSystemObject")
set objFile = objFS.GetFile(PW_GetJobFilename)
set objTS = objFile.OpenAsTextStream(ForReading)
strDataCapture = objTS.Read(objFile.Size)
objfile.close
Do while strDataCapture.AtEndOfFile <>true
strDataCapture.Replace("\x00","\x20")
strDataCapture.Replace("\x0d""\x0a""\x01","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x09","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x0b","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x11","\x0d""\x0a""\x30")
strDataCapture.Replace("\x0d""\x0a""\x13","\x0d""\x0a""\x30")
strDataCapture.Replace("\x0d""\x0a""\x19","\x0d""\x0a""\x2d")
strDataCapture.Replace("\x0d""\x0a""\x1b","\x0d""\x0a""\x2d")
strDataCapture.Replace("\x0d""\x0a""\x2a","\x0d""\x0a""\x20""\x2a")
strDataCapture.Replace("\x0d""\x0a""\x69","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x8b","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x8d","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x8f","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\xbb","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0c","\x0d""\x0a""\x31")
strDataCapture.Replace("\x9e","\x4f")
strDataCapture.Replace("\xa6","\x1b")
loop
Set objFile = objFS.OpenTextFile(PW_GetJobFileName, ForWriting)
objFile.Write strDataCapture
objFile.Close
As you can see, I have a LOT of strings to search and replace.
I'm not sure if I have the replace loop correct, or if it's even necessary with that command. I'm also uncertain as to how to properly write the whole mess back to the file properly.
All the code above is mish-mashed together from a lot of different sites with my very limited understanding and I'm hoping I at least got some of it right.
I appreciate all the help and insight I've received from this forum, both in answers received and other posts I've read.
ShopMonkey
I found a website with some variations on reading large files ( ) and the technet "Scripting Guy" article on searching and replacing text in a file ( )
Since the files I'm working with can be extremely large (80mb+ ) I chose to use the "read byte" method I found on the first reference site and the following is the code I came up with after combining the two:
const ForReading = 1
Const ForWriting = 2
const TristateFalse = 0
dim strDataCapture
dim objFS
dim objFile
dim objTS
set objFS = CreateObject("Scripting.FileSystemObject")
set objFile = objFS.GetFile(PW_GetJobFilename)
set objTS = objFile.OpenAsTextStream(ForReading)
strDataCapture = objTS.Read(objFile.Size)
objfile.close
Do while strDataCapture.AtEndOfFile <>true
strDataCapture.Replace("\x00","\x20")
strDataCapture.Replace("\x0d""\x0a""\x01","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x09","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x0b","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x11","\x0d""\x0a""\x30")
strDataCapture.Replace("\x0d""\x0a""\x13","\x0d""\x0a""\x30")
strDataCapture.Replace("\x0d""\x0a""\x19","\x0d""\x0a""\x2d")
strDataCapture.Replace("\x0d""\x0a""\x1b","\x0d""\x0a""\x2d")
strDataCapture.Replace("\x0d""\x0a""\x2a","\x0d""\x0a""\x20""\x2a")
strDataCapture.Replace("\x0d""\x0a""\x69","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x8b","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0a""\x8d","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\x8f","\x0d""\x0a""\x20")
strDataCapture.Replace("\x0d""\x0a""\xbb","\x0d""\x0a""\x31")
strDataCapture.Replace("\x0d""\x0c","\x0d""\x0a""\x31")
strDataCapture.Replace("\x9e","\x4f")
strDataCapture.Replace("\xa6","\x1b")
loop
Set objFile = objFS.OpenTextFile(PW_GetJobFileName, ForWriting)
objFile.Write strDataCapture
objFile.Close
As you can see, I have a LOT of strings to search and replace.
I'm not sure if I have the replace loop correct, or if it's even necessary with that command. I'm also uncertain as to how to properly write the whole mess back to the file properly.
All the code above is mish-mashed together from a lot of different sites with my very limited understanding and I'm hoping I at least got some of it right.
I appreciate all the help and insight I've received from this forum, both in answers received and other posts I've read.
ShopMonkey