Const LogPath = "X:\Logs\"
Logfile = LogPath & "DataFix-" & FormatDateTime(Date, 1) & ".Log"
LogEvent ( "***************************************")
LogEvent ( "***************Started****************")
LogEvent ( "***************************************")
DataFix "X:\VBIN\", "X:\VOUT"
LogEvent ( "***************************************")
LogEvent ( "***************Finished****************")
LogEvent ( "***************************************")
Sub DataFix(sourceFolder,targetDir)
On Error Resume next
set objFSO = CreateObject("Scripting.FileSystemObject")
set objDir = objFSO.GetFolder(sourceFolder)
for each a in objDir.Files
LogEvent ("Opening " & a)
numlines = 1
gotHeader = False
HeaderText_FirstLine = ""
HeaderText_SecondLine = ""
HeaderText_ThirdLine = ""
IsThisBTEST = False
IsException = False
set objTextFile = objFSO.OpenTextFile(a)
filename = objFSO.GetFileName(a)
new1 = targetDir + "\" + left(filename, len(filename) - 4) + "_New" + right(filename, 4)
set w1 = objFSO.CreateTextFile(new1, True)
do until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
'If number of lines is greater than 37 then do below
Select case left(strLine, 7)
Case "- ACM0"
strline = Replace (strLine, "1", "2", 1,1)
End select
select case left(strLine, 7)
case "- ACM0"
IsThisBTEST = True
LogEvent ("This is a valid file, continuing...")
HeaderText_FirstLine = strLine
If Right(strLine, 5) = "1000E" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 13)
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
If Right(strLine, 5) = "AAAAU" OR Right(strLine, 5) = "AAAB6" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
End If
End If
case else
if IsThisBTEST = True then
w1.WriteLine strLine
end if
end select
if IsThisBTEST = True then
if numlines = 2 and Len(HeaderText_FirstLine) > 0 then
if IsException = False Then
HeaderText_SecondLine = strLine
else
HeaderText_SecondLine = "1000E"
end If
end if
if numlines = 3 and Len(HeaderText_FirstLine) > 0 and Len(HeaderText_SecondLine) > 0 then
HeaderText_ThirdLine = strLine
gotHeader = True
end if
if gotHeader = True and numlines = 31 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
if gotHeader = True and numlines = 33 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
numlines = numlines + 1
end if
loop
w1.Close
if IsThisBTEST = False then
LogEvent ("Not a valid file - No modifications made to file.")
objFSO.DeleteFile (new1)
else
LogEvent ("Completed file manipulation successfully. New file written to " & new1)
end if
LogEvent ("")
LogEvent ("Deleting original file...")
objTextFile.Close
objFSO.DeleteFile (a)
LogEvent ("")
next
set objFSO = nothing
IF err.number <> 0 THEN
LogEvent ("Error # " & CStr(Err.Number) & " " & Err.Description)
END IF
End Sub
'**********************************************************************
'* @name LogEvent([])
'* @param
'* @purpose
'* @return
'*************************************************************************
sub LogEvent (sEvent)
Dim fso
Dim Log
set fso = wscript.createobject("scripting.filesystemobject")
Set Log = fso.OpenTextFile(LogFile, 8, True)
log.writeline Time & chr(9) & sEvent
'WScript.Echo(sEvent)
log.close
set fso = nothing
End Sub
Const LogPath = "X:\Logs\"
Logfile = LogPath & "DataFix-" & FormatDateTime(Date, 1) & ".Log"
LogEvent ( "***************************************")
LogEvent ( "***************Started****************")
LogEvent ( "***************************************")
DataFix "X:\VBIN\", "X:\VOUT"
LogEvent ( "***************************************")
LogEvent ( "***************Finished****************")
LogEvent ( "***************************************")
Sub DataFix(sourceFolder,targetDir)
On Error Resume next
set objFSO = CreateObject("Scripting.FileSystemObject")
set objDir = objFSO.GetFolder(sourceFolder)
for each a in objDir.Files
LogEvent ("Opening " & a)
numlines = 1
gotHeader = False
HeaderText_FirstLine = ""
HeaderText_SecondLine = ""
HeaderText_ThirdLine = ""
IsThisBTEST = False
IsException = False
set objTextFile = objFSO.OpenTextFile(a)
filename = objFSO.GetFileName(a)
new1 = targetDir + "\" + left(filename, len(filename) - 4) + "_New" + right(filename, 4)
set w1 = objFSO.CreateTextFile(new1, True)
TotalLinesInFile=0
do until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
'If number of lines is greater than 37 then do below\
if TotalLinesInFile>37 then
Select case left(strLine, 7)
Case "- ACM0"
strline = Replace (strLine, "1", "2", 1,1)
End select
select case left(strLine, 7)
case "- ACM0"
IsThisBTEST = True
LogEvent ("This is a valid file, continuing...")
HeaderText_FirstLine = strLine
If Right(strLine, 5) = "1000E" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 13)
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
If Right(strLine, 5) = "AAAAU" OR Right(strLine, 5) = "AAAB6" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
End If
End If
case else
if IsThisBTEST = True then
w1.WriteLine strLine
end if
end select
if IsThisBTEST = True then
if numlines = 2 and Len(HeaderText_FirstLine) > 0 then
if IsException = False Then
HeaderText_SecondLine = strLine
else
HeaderText_SecondLine = "1000E"
end If
end if
if numlines = 3 and Len(HeaderText_FirstLine) > 0 and Len(HeaderText_SecondLine) > 0 then
HeaderText_ThirdLine = strLine
gotHeader = True
end if
if gotHeader = True and numlines = 31 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
if gotHeader = True and numlines = 33 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
numlines = numlines + 1
end if
loop
w1.Close
if IsThisBTEST = False then
LogEvent ("Not a valid file - No modifications made to file.")
objFSO.DeleteFile (new1)
else
LogEvent ("Completed file manipulation successfully. New file written to " & new1)
end if
LogEvent ("")
LogEvent ("Deleting original file...")
objTextFile.Close
objFSO.DeleteFile (a)
LogEvent ("")
end if
TotalLinesInFile=TotalLinesInFile+1
next
set objFSO = nothing
IF err.number <> 0 THEN
LogEvent ("Error # " & CStr(Err.Number) & " " & Err.Description)
END IF
End Sub
'**********************************************************************
'* @name LogEvent([])
'* @param
'* @purpose
'* @return
'*************************************************************************
sub LogEvent (sEvent)
Dim fso
Dim Log
set fso = wscript.createobject("scripting.filesystemobject")
Set Log = fso.OpenTextFile(LogFile, 8, True)
log.writeline Time & chr(9) & sEvent
'WScript.Echo(sEvent)
log.close
set fso = nothing
End Sub
Const LogPath = "X:\Logs\"
Logfile = LogPath & "DataFix-" & FormatDateTime(Date, 1) & ".Log"
LogEvent ( "***************************************")
LogEvent ( "***************Started****************")
LogEvent ( "***************************************")
DataFix "X:\VBIN\", "X:\VOUT"
LogEvent ( "***************************************")
LogEvent ( "***************Finished****************")
LogEvent ( "***************************************")
Sub DataFix(sourceFolder,targetDir)
On Error Resume next
set objFSO = CreateObject("Scripting.FileSystemObject")
set objDir = objFSO.GetFolder(sourceFolder)
for each a in objDir.Files
LogEvent ("Opening " & a)
numlines = 1
gotHeader = False
HeaderText_FirstLine = ""
HeaderText_SecondLine = ""
HeaderText_ThirdLine = ""
IsThisBTEST = False
IsException = False
set objTextFile = objFSO.OpenTextFile(a)
filename = objFSO.GetFileName(a)
new1 = targetDir + "\" + left(filename, len(filename) - 4) + "_New" + right(filename, 4)
set w1 = objFSO.CreateTextFile(new1, True)
TotalLinesInFile=0
do until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
'If number of lines is greater than 37 then do below\
if TotalLinesInFile>37 then
Select case left(strLine, 7)
Case "- ACM0"
strline = Replace (strLine, "1", "2", 1,1)
End select
select case left(strLine, 7)
case "- ACM0"
IsThisBTEST = True
LogEvent ("This is a valid file, continuing...")
HeaderText_FirstLine = strLine
If Right(strLine, 5) = "1000E" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 13)
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
If Right(strLine, 5) = "AAAAU" OR Right(strLine, 5) = "AAAB6" Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
w1.WriteLine "1000E"
IsException = True
numlines = numlines + 1
Else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
End If
End If
case else
if IsThisBTEST = True then
w1.WriteLine strLine
end if
end select
if IsThisBTEST = True then
if numlines = 2 and Len(HeaderText_FirstLine) > 0 then
if IsException = False Then
HeaderText_SecondLine = strLine
else
HeaderText_SecondLine = "1000E"
end If
end if
if numlines = 3 and Len(HeaderText_FirstLine) > 0 and Len(HeaderText_SecondLine) > 0 then
HeaderText_ThirdLine = strLine
gotHeader = True
end if
if gotHeader = True and numlines = 31 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1003" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
if gotHeader = True and numlines = 33 then
if IsException = False Then
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)
else
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1004" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16)&"FED"
end if
end if
numlines = numlines + 1
end if 'if IsThisBTEST
end if 'if >37
loop
w1.Close
if IsThisBTEST = False then
LogEvent ("Not a valid file - No modifications made to file.")
objFSO.DeleteFile (new1)
else
LogEvent ("Completed file manipulation successfully. New file written to " & new1)
end if
LogEvent ("")
LogEvent ("Deleting original file...")
objTextFile.Close
objFSO.DeleteFile (a)
LogEvent ("")
TotalLinesInFile=TotalLinesInFile+1
next
set objFSO = nothing
IF err.number <> 0 THEN
LogEvent ("Error # " & CStr(Err.Number) & " " & Err.Description)
END IF
End Sub
'**********************************************************************
'* @name LogEvent([])
'* @param
'* @purpose
'* @return
'*************************************************************************
sub LogEvent (sEvent)
Dim fso
Dim Log
set fso = wscript.createobject("scripting.filesystemobject")
Set Log = fso.OpenTextFile(LogFile, 8, True)
log.writeline Time & chr(9) & sEvent
'WScript.Echo(sEvent)
log.close
set fso = nothing
End Sub
Do While objTextFile.AtEndOfStream <> True
objTextFile.SkipLine
Loop
NumLines=objTextFile.Line-1
'close the file
objTextFile.Close
if (NumLines) > 37 then
'reopen the file and process it with whatever code you want--knowing that there are more than 37 lines
end if
http://gnuwin32.sourceforge.net/packages/coreutils.htm
The good old unix/linux tool wc does exactly this and with these tools is available on Windows
wc.exe -l yourtextfile.txt
will return the number of lines in the text file
Natively, you could do this in a batch file
type yourtextfile.txt | find /V /C ""