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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote folder delete from list of machine names

Status
Not open for further replies.

butcha33

Technical User
Apr 11, 2008
3
Hi, i am having problems with th ebelow code. I cant figure out how to correct the issue. Any help will be appreciated.

Thank you

================================================



'------------------read text file--------------------------

set objShell = CreateObject("Wscript.Shell")

strPath = Wscript.ScriptFullName

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.GetFile(strPath)

strFolder = objFSO.GetParentFolderName(objFile)

strInputFile = strFolder & "\computernames.txt"

'---------------'function to build array from text file.---


Function ReadTextFile(strInputFile)

On Error Resume Next

Const FOR_READING = 1

Set objFSO = CreateObject(Scripting.FileSystemObject)

Set objTextStream = objFSO.OpenTextFile(strInputFile, FOR_READING)

arrLines = Split(objTextStream.ReadAll, vbCrLf)
objTextStream.Close

ReadTextFile = arrLines

End Function

'---------------------------------------------------

For Each strItem In ReadTextFile(strInputFile)
Set objShell = CreateObject("WScript.Shell")


'--------------------------Delete remote folder-----------

'msgbox strItem

Dim arrFolders()
intSize = 0

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


strFolderName = "c:\test"


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

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


Next
==============================================
 
i am having problems with th ebelow code
Which problem ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
sorry, the script is made of two parts. one that reads the text file and reads back each line(computername). this info is then put into part two which deletes a folder on that machine.

now both parts work seperately but once combined i get a syntax error on

Sub GetSubFolders(strFolderName)

any help will be very helpful

thank you
 
Do you have the sub getsubfolders actually inside the other code?

Your code you posted does not make any sense.

You have code
then a function in the middle of code
more code
then a sub procedure
then more code

Copy and paste your code as it is actually in the module. If this is how it actually is then move the function and procedure from within the other procedure and just call the function and procedure where needed

ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top