I've got an issue on loop in vbs
My script is reading a file line per line and do some tasks. I put on error resume next.
When an error occurs, script continues loop BUT with the next argument (the next line). Is there a tips to make script continue loop with the same argument?
Here is the script.
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
I'm sorry it seems to work.
I modified this on log :
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
by
objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description
Now the log is ok. It continues. Sorry for this :)
In case of error, your
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description
reads/uses up the next line from your source file. Use
objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.