我在vbs循环中遇到了问题
我的脚本每行读取一个文件行并执行一些任务。 我接下来就把错误恢复了。
当发生错误时,脚本继续循环BUT并使用下一个参数(下一行)。 是否有提示使用相同的参数使脚本继续循环?
这是脚本。
on error resume next
dim filesys, text, readfile, contents, copy, oNet, objLog
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("xxxx", 1, false)
set copy = CreateObject("Scripting.FileSystemObject")
set oNet = CreateObject("Wscript.Network")
set objLog = filesys.OpenTextFile("xxxx", 8, true)
do while readfile.AtEndOfStream=false
objLog.WriteLine "0"
contents = readfile.ReadLine
Drive = "Z:"
User = "xxx"
Pass = "xxx"
PER = "FALSE"
Share = "\\" & contents & "\c$\windows\temp"
oNet.MapNetworkDrive Drive, Share, PER, User, Pass
objLog.WriteLine "1"
If Err.Number <> 0 Then
objLog.WriteLine "1.1"
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
' wscript.echo "ATTENTION: " & Err.Description
Err.Clear
End If
copy.CopyFile "Z:\xxx", "xxx" & contents & ".log"
objLog.WriteLine "2"
If Err.Number <> 0 Then
objLog.WriteLine "2.1"
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
' wscript.echo "ATTENTION: " & Err.Description
Err.Clear
End If
objLog.WriteLine "3"
WScript.Sleep 5000
oNet.RemoveNetworkDrive "Z:"
objLog.WriteLine "4"
loop
readfile.close
答案 0 :(得分:0)
我很抱歉它似乎有效。
我在日志中对此进行了修改:
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
通过
objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description
现在日志还可以。它继续。对不起:)
答案 1 :(得分:0)
如果出现错误,您的
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
读取/用完源文件中的下一行。使用
objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description
代替。