簡體   English   中英

VBS循環問題

[英]VBS on loop issue

我在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

對不起,它似乎起作用了。

我在日志上修改了這個:

objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description

通過

objLog.WriteLine contents  & " ---- ATTENTION: " & Err.Description

現在日志可以了。 它繼續。 非常遺憾 :)

如果發生錯誤,您的

objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description

從源文件讀取/使用下一行。 采用

objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description

代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM