Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement causing a syntax error.

Status
Not open for further replies.

ChuckG

MIS
Feb 28, 2001
211
US
Have a script that without the IF. ELSEIF statement works fine, but I need the if.elseif so that I don't run through the entire thing everytime, only when a certain field is equal to "Home Dir Archive"

But I keep getting a Syntax error on the line with the SUB Getfolders.

I'm probably overlooking something REALLY simple.

Here's the code I'm using


'Delete folder and all subfolders

'open excel file
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("h:\Scripts\Med_Disabled.xls")
objExcel.Visible = True

objExcel.Cells(1,7) = "Home-Deleted?"
y = 2

Do Until objExcel.Cells(y, 1).Value = ""
strStatus = objExcel.Cells(y,6)
dir1 = ObjExcel.Cells(y,2)

if strStatus = "Home Dir could not be reached" then
objExcel.Cells(y,7) = "WARNING - Could not reach check manually"

elseif strStatus = "No Dir on file" then
objExcel.Cells(y,7) = "No Home dir assigned"

elseif strStatus = "Home Dir Archived" then

' START OF MY IF STATEMENT
'Parse out folder name and share location for mapping
Folder_len_start = InStrRev(dir1,"\")
String_len = len(dir1)

folder_name = right(dir1,(string_len - Folder_len_start))
folder_name = "Y:\" & folder_name
dir_map = left(dir1,(Folder_len_start -1))

'Map out the drive to do deletion on
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "Y:" , dir_map


Dim arrFolders()
intSize = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = folder_name


Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1

For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next

'THIS NEXT LINE IS WHERE THE SYNTAX ERROR OCCURS
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
GetSubFolders strFolderName
Next
End Sub

For i = Ubound(arrFolders) to 0 Step -1
strFolder = arrFolders(i)
strFolder = Replace(strFolder, "\", "\\")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = '" & strFolder & "'")

For Each objFolder in colFolders
errResults = objFolder.Delete
Next
Next

'Unmap network drive
Dim objNetwork, strDriveLetter
strDriveLetter = "Y:"

Set objNetwork = CreateObject("WScript.Network")
' Section which removes strDriveLetter
objNetwork.RemoveNetworkDrive strDriveLetter
'WHERE I WANT THE IF STATEMENT TO END
end if
Loop



ChuckG
-=-=-=-
Midnight Club BBS
telnet midnight-club.org
 
Put the whole GetSubFolders procedure AFTER the Loop instruction ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top