This is strange: The script works perfectly when run by double clicking [outputs the (split)arc files], when textFile is hard coded. When dragging and dropping the file onto the script, there are no errors but also no output files. The script definitely runs when using drag and drop, I added a simple message box to the line just before writeTo, to confirm that it does reach that point. No files output when dragging and dropping though, only works correctly when textFile is hard coded. Someone please help!
if WScript.Arguments.Count <> 0 then
textFile = WScript.Arguments(0)
else
textFile = "multi2.txt"
end if
saveTo = ""
writeTo = ""
strNewLine = "%_N_"
headingPattern = "(%_N_)"
dim fileFrom, regex, fileTo
Set fso = CreateObject("Scripting.FileSystemObject")
set fileFrom = fso.OpenTextFile(textFile)
set regex = new RegExp
set fileTo = nothing
with regex
.Pattern = headingPattern
.IgnoreCase = false
.Global = true
end with
while fileFrom.AtEndOfStream <> true
line = fileFrom.ReadLine
set matches = regex.Execute(line)
if matches.Count > 0 then
strCheckForString = UCase("%")
strNewLine = "%_N_"
StrContents = Split(fso.OpenTextFile(textFile).ReadAll, vbNewLine)
If (Left(UCase(LTrim(line)),Len(strCheckForString)) = strCheckForString) Then
line = Right(line, len(line)-4)
line1 = Left(line, len(line)-4)
writeTo = saveTo & (line1 & ".arc")
if not(fileTo is nothing) then fileTo.Close()
set fileTo = fso.CreateTextFile(writeTo)
fileTo.WriteLine(strNewLine & line)
else
fileTo.WriteLine(line)
End If
else
fileTo.WriteLine(line)
end if
wend
fileFrom.Close()
set fileFrom = nothing
set fso = nothing
set regex = nothing
The text file looks like this:
%_N_160_SP01_MPF
;$PATH=/_N_WKS_DIR/_N_AFO160_WPD
blah blah blah
%_N_160_SP02_MPF
;$PATH=/_N_WKS_DIR/_N_AFO160_WPD
blah blah blah
%_N_160_SP99_MPF
;$PATH=/_N_WKS_DIR/_N_AFO160_WPD
blah blah blah