添加输入文件日期检查时的代码性能

时间:2019-05-30 00:05:42

标签: vbscript

通过以下更改,代码的运行时间从不到5分钟增加到一个小时以上:

发件人:

If objFSO.FileExists(inputFile) then

收件人:

If FormatDateTime(objFile.DateLastModified,vbShortDate) = FormatDateTime(Date,vbShortDate) Then

我尝试仅对文件是否存在进行初始检查,并将输入文件日期检查移到代码底部。

这并没有改善运行时间

Dim arrName     昏暗的arrFields     昏暗的strName

Dim inputFile : inputFile = "\\dgdgdgd\xyx.csv"
Dim newInputFile : newInputFile = "xyx_NEW.csv"
Dim fileLocation : fileLocation = "....csv"
Dim inputgz: inputgz = "...xyx.csv.gz"
Dim archivegz: archivegz ="...xyx.csv."& Year(date) & Month(date) & 
Day(date)&".gz"
Dim wLine : wLine = ""
Dim numLine : numLine = 0


Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile=objFso.GetFile(inputFile)
If FormatDateTime(objFile.DateLastModified,vbShortDate) = 
FormatDateTime(Date,vbShortDate) Then

'No date check
'If objFSO.FileExists(inputFile) then
        objFile.Copy newInputFile
    Set objRead = objFSO.OpenTextFile(newInputFile, ForReading)
    Set objWrite = objFSO.CreateTextFile(fileLocation)
else
writeToLog("ERROR: File is not current (" & inputFile & ")")
objFso.DeleteFile(inputFile)
wscript.quit
End If


strLine = objRead.ReadLine
objWrite.WriteLine(strLine)

writeToLog("Read Input file and find records that match XYZ in 14, 17 and 18 fields")

Do Until objRead.AtEndOfStream

strLine = objRead.ReadLine
objWrite.WriteLine(strLine)
Do Until objRead.AtEndOfStream
strLine = objRead.ReadLine
arrFields = Split(strLine, vbTab)
IF instr(arrFields(14),"XYZ") > 0 OR instr(arrFields(17),"XYZ") > 0 OR 
instr(arrFields(18),"XYZ") > 0 THEN
objWrite.WriteLine(strLine)
END IF


Loop

objRead.Close()
objWrite.Close()

Sub writeToLog(theString)
    wscript.echo(Date & " - " & Time & " - " & theString)
End Sub

理想的运行时间最好在10分钟以内。

0 个答案:

没有答案