|
-
Sep 30th, 2005, 02:04 PM
#1
Thread Starter
New Member
loop without do error
I am in the process of learning windows scripting and have run into a problem.
I have been asked to get a script working that was started by another user that is no longer with the company I am working for. The script is suppose to pull a zip file from our web servers over to another server and unzip them to the correct directories for processing through and application called clicktracks. currently I am getting an error stating "Loop without do" and I can't figure out what the problem is.
Here is an sample of the code
VB Code:
Option Explicit
'Declare Variables
Dim objFSO,objWSHShell,objInFile,objFolder,objFile,objZipFolder,objZipFile,objLogFile
Dim strDate,strMonth,strYear,strDay,strTargetFile1,strTargetfile2,strDeleteDate
Dim strServer,strImageLib,strPrimaryWS,strVirtualWS,strStage,strSyntax,strExt,strZip
Dim arrWebServerList,strFolder1,strFolder2,strFolder3,strFolder4,strFolder5,strFile1
Dim strFile2,strFile3,strMovefile,strNetUse,strSource,strOutFile
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSHShell = CreateObject("WScript.Shell")
Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
'Determin Target Date
strDate = Now()-1
strMonth = CStr(Month(strDate))
strYear = Right(CStr(Year(strDate)),2)
strDay = CStr(Day(strDate))
'If Month Single Digit then pad with leading zero
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
'If Day Single Digit then pad with leading Zero
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
'Determin Target Files
strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
'Target Delete Date
'strDeleteDate = Date -32
'Read Web Server List
Do While Not objInFile.AtEndOfStream
arrWebServerList = Split(objInFile.ReadLine,",")
strServer= arrWebServerList(0)
strImageLib = arrWebServerList(1)
strPrimaryWS = arrWebServerList(2)
strVirtualWS = arrWebServerList(3)
strStage = "D:\" & strServer & "\"
strZip = "c:\winzip\winzip32"
strFile1 = strPrimaryWS & strTargetfile2
strFile2 = strVirtualWS & strTargetfile2
strFile3 = strImageLib & strTargetfile2
'Authenticate to Web Server
strNetUse = "cmd /c netuse \\" & strServer & (Login information for server)
objWSHShell.Run strNetUse,0,True
'Zip file Exist on Server
If objFSO.FileExists ("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
'Copy zip file From WebServer
objFOS.Copyfile objFile.Path, strStage & "\"
'UnZip File to Local Directory
strSyntax = strZip & " -e " & stgStage & "\" & strTargetFile1 & " " & "C:\"
objWSHShell.Run strSyntax,0,True
'Move File to Destination Directory
If objFSO.FileExists ("c:\" & strFile1) Then
objFSO.MoveFile strStage & strPrimaryWS & "\"
If objFSO.FileExists ("c:\" & strFile2) Then
objFSO.MoveFile strStage & strVirtualWS & "\"
If objFSO.FileExists ("c:\" & strFile3) Then
objFSO.MoveFile strStage & strImageLib & "\"
Elseif strExt = ".zip" Then
objFSO.MoveFile objLogFile.Path,strStage & "completedZips\"
'Disconnect From Web Server
strNetUse = "cmd /c netuse \\" & strServer & /d"
objWSHShell.Run strNetUse,0
End If
Loop
-
Sep 30th, 2005, 02:08 PM
#2
Re: loop without do error
check you "IF's" you seem to be missing some "End If's"
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 30th, 2005, 02:15 PM
#3
Re: loop without do error
Are the line continuation characters not showing? Or are they really not in the code?
If...then...elseif is not being processed correctly if _ isn't there.
-
Sep 30th, 2005, 02:16 PM
#4
Fanatic Member
Re: loop without do error
I'm not sure what you are trying to do with all those if statements down at the bottom but for 4 if statements you have only one End If. If each of those are supposed to be seperate ifs then you need to properly end each one of them with an end if.
typical if statement syntax is
VB Code:
If variable = something Then
Else 'Optional You dont have to have an else
End If
you can do
VB Code:
If something = somethingelse Then
ElseIf something = somethingelse Then
ElseIf ...... you get the picture
End If
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Sep 30th, 2005, 02:18 PM
#5
Re: loop without do error
or even
IF Something then Something
but if you go to another line after "Then" then you need an end if for each If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 30th, 2005, 04:25 PM
#6
Re: loop without do error
rhyatt,
That's some really bad coding. First try indenting your if statement to give you a better understanding of what is executed under what conditions. But you definitely need some End If statements in there somewhere.
-
Sep 30th, 2005, 04:32 PM
#7
Re: loop without do error
rhyatt,
Your code would actually be clearer if it was structured in this manner:
Code:
'Declare Variables
Dim objFSO, objWSHShell, objInFile, objFolder, objFile, objZipFolder, objZipFile, objLogFile
Dim strDate, strMonth, strYear, strDay, strTargetFile1, strTargetfile2, strDeleteDate
Dim strServer, strImageLib, strPrimaryWS, strVirtualWS, strStage, strSyntax, strExt, strZip
Dim arrWebServerList, strFolder1, strFolder2, strFolder3, strFolder4, strFolder5, strFile1
Dim strFile2, strFile3, strMovefile, strNetUse, strSource, strOutFile
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSHShell = CreateObject("WScript.Shell")
Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
'Determin Target Date
strDate = Now() - 1
strMonth = CStr(Month(strDate))
strYear = Right(CStr(Year(strDate)), 2)
strDay = CStr(Day(strDate))
'If Month Single Digit then pad with leading zero
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
'If Day Single Digit then pad with leading Zero
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
'Determin Target Files
strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
'Target Delete Date
'strDeleteDate = Date -32
'Read Web Server List
Do While Not objInFile.AtEndOfStream
arrWebServerList = Split(objInFile.ReadLine, ",")
strServer = arrWebServerList(0)
strImageLib = arrWebServerList(1)
strPrimaryWS = arrWebServerList(2)
strVirtualWS = arrWebServerList(3)
strStage = "D:\" & strServer & "\"
strZip = "c:\winzip\winzip32"
strFile1 = strPrimaryWS & strTargetfile2
strFile2 = strVirtualWS & strTargetfile2
strFile3 = strImageLib & strTargetfile2
'Authenticate to Web Server
strNetUse = "cmd /c netuse \\" & strServer & (Login information for server)
objWSHShell.Run strNetUse, 0, True
'Zip file Exist on Server
If objFSO.FileExists("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
'Copy zip file From WebServer
objFOS.Copyfile objFile.Path, strStage & "\"
'UnZip File to Local Directory
strSyntax = strZip & " -e " & stgStage & "\" & strTargetFile1 & " " & "C:\"
objWSHShell.Run strSyntax, 0, True
'Move File to Destination Directory
If objFSO.FileExists("c:\" & strFile1) Then
objFSO.MoveFile strStage & strPrimaryWS & "\"
Else
If objFSO.FileExists("c:\" & strFile2) Then
objFSO.MoveFile strStage & strVirtualWS & "\"
Else
If objFSO.FileExists("c:\" & strFile3) Then
objFSO.MoveFile strStage & strImageLib & "\"
ElseIf strExt = ".zip" Then
objFSO.MoveFile objLogFile.Path, strStage & "completedZips\"
'Disconnect From Web Server
strNetUse = "cmd /c netuse \\" & strServer & /d"
objWSHShell.Run strNetUse, 0
End If
End If
End If
End If
Loop
-
Sep 30th, 2005, 04:42 PM
#8
Re: loop without do error
Shouldn't you always disconnect from the server? Right now it's in the IF statement.
-
Oct 3rd, 2005, 11:20 AM
#9
Thread Starter
New Member
Re: loop without do error
Everyone
Thanks you for your help on this problem. As Randem suggested I modified and cleaned up the code some. My only problems now is once the files are unzipped they do not move to the proper folders and the script does not loop. For what ever if I user this
VB Code:
Set objFile1 = objFSO.GetFile("C:\" & strFile1)
objFSO.MoveFile objFile1.path,strStage & "\" & strPrimaryWS & "\"
It works fine. but with this
VB Code:
objFSO.MoveFile strStage & "\" & strPrimaryWS & "\"
the log files will not be moved.
Here is a copy of the updated code. any suggestions on the movefile problem or the non looping issue would be great.
VB Code:
Option Explicit
On Error Resume Next
'Declare Variables
Dim objFSO,objWSHShell,objInFile,objFolder,objFile,objZipFolder,objZipFile,objLogFile,objFile1,objFile2,objFile3,objOutFile
Dim strDate,strMonth,strYear,strDay,strTargetFile1,strTargetfile2,strDeleteDate
Dim strServer,strImageLib,strPrimaryWS,strVirtualWS,strStage,strSyntax,strExt,strZip
Dim arrWebServerList,strFolder1,strFolder2,strFolder3,strFile1
Dim strFile2,strFile3,strMovefile,strNetUse,strSource,strOutFile
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSHShell = CreateObject("WScript.Shell")
Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
'Determin Target Date
strDate = Now()-1
strMonth = CStr(Month(strDate))
strYear = Right(CStr(Year(strDate)),2)
strDay = CStr(Day(strDate))
'If Month Single Digit then pad with leading zero
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
'If Day Single Digit then pad with leading Zero
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
'Determin Target Files
strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
'Target Delete Date
'strDeleteDate = Date -32
'Read Web Server List
Do While Not objInFile.AtEndOfStream
arrWebServerList = Split(objInFile.ReadLine,",")
strServer= arrWebServerList(0)
strImageLib = arrWebServerList(1)
strPrimaryWS = arrWebServerList(2)
strVirtualWS = arrWebServerList(3)
strStage = "c:\PioWebLogs\" & strServer
strZip = "c:\winzip\winzip32"
strFolder1 = strStage & "\" & strPrimaryWS
strFolder2 = strStage & "\" & strVirtualWS
strFolder3 = strStage & "\" & strImageLib
strFile1 = strPrimaryWS & strTargetfile2
strFile2 = strVirtualWS & strTargetfile2
strFile3 = strImageLib & strTargetfile2
'Create Log file
Set objOutFile = objFSO.CreateTextFile("C:\PioWebLogs\" & strServer & "_LogResults.Log")
Const forWriting = 2
objOutFile.WriteLine "Web Log Pulls Results Log"
objOutFile.WriteLine Now() & vbTab & "Process Started"
'Authenticate to Web Server
objOutFile.WriteLine Now() & vbTab & "Authenticate to Web Server: " & strServer
'objOutFile.WriteLineBlankLines(1)
strNetUse = "cmd /c netuse \\" & strServer & "Logon information"
objWSHShell.Run strNetUse,0,True
'Zip file Exist on Server
If objFSO.FileExists ("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
objOutFile.WriteLine Now() & vbTab & "File Exists: " & strTargetFile1
Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
'Copy zip file From WebServer
objOutFile.WriteLine Now() & vbTab & "Move Zip File From Web Server: \\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1
objFSO.Copyfile objFile.Path,strStage & "\CompletedZips\"
'UnZip File to Local Directory
strSyntax = strZip & " -e -o " & strStage & "\CompletedZips\" & strTargetFile1 & " " & "C:\"
objOutFile.WriteLine Now() & vbTab & "Unzip File to Local Directory: " & strSyntax
objWSHShell.Run strSyntax,0,True
'Move File to Destination Directory
objOutFile.WriteLine Now() & vbTab & "Move file to Destination Directory"
If objFSO.FileExists ("c:\" & strFile1) Then
objOutFile.WriteLine Now() & vbTab & " Move " & objFile1 & " To " & strStage & "\" & strPrimaryWS & "\"
objFSO.MoveFile strStage & "\" & strPrimaryWS & "\"
Else
If objFSO.FileExists ("c:\" & strFile2) Then
objOutFile.WriteLine Now() & vbTab & " Move " & objFile2 & " To " & strStage & "\" & strPrimaryWS & "\"
objFSO.MoveFile strStage & "\" & strVirtualWS & "\"
Else
If objFSO.FileExists ("c:\" & strFile3) Then
objOutFile.WriteLine Now() & vbTab & " Move " & objFile3 & " To " & strStage & "\" & strPrimaryWS & "\"
objFSO.MoveFile strStage & "\" & strImageLib & "\"
'Disconnect From Web Server
strNetUse = "cmd /c netuse \\" & strServer & "\IPC$ /d"
objWSHShell.Run strNetUse,0
End If
End If
End If
End If
Loop
objOutFile.WriteLine Now() & vbTab & "Process Complete"
objOutFile.Close
Last edited by rhyatt; Oct 3rd, 2005 at 11:47 AM.
-
Oct 3rd, 2005, 11:55 AM
#10
Re: loop without do error
Because the objFSO.MoveFile methods needs two information to be able to move files... and that is the source path and the destination path (comma separated. You only plugged in one value in your erroneous line
-
Oct 3rd, 2005, 12:34 PM
#11
Thread Starter
New Member
Re: loop without do error
Everyone
Thanks again for your help on this problem. I made a few more changes and got the script working. It loops through the file and everything is being moved to it's correct location.
Thanks again
Ron
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|