Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

vbscript to delete files & folders of remote computer

$
0
0

Hi Greeting,

 

First thing I am not an expert in writing VBScripts.

 

I have a requirement of deleting files & folders of remote systems with just 1 click. I was trying to build below VBScript but somehow it’s not working. I request any of your help to correct the same or with a new script that help me to fulfill the requirement. Any help in this regard is greatly appreciated, Thanks in Advance.

 

With the below:

C:\Test -  is the directory from where I would like to delete the files & subfolders

C:\computerList.txt – is the text file contains all remote systems IP Address.

 

 

Const strPath = "C:\Test"

 

Set computerList = objfso.OpenTextFile ("C:\computerList.txt", 1)

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

Call Search (strPath)

WScript.Echo"Done."

 

Sub Search(str)

    Do While Not computerList.AtEndOfStream

               strComputer = computerList.ReadLine

                               Dim objFolder, objSubFolder, objFile

                               Set objFolder = objFSO.GetFolder("\\" & strComputer & "\" & str)

                               For Each objFile In objFolder.Files

                                               If objFile.DateLastModified < (Now() - 0) Then

                                                               objFile.Delete(True)

                                               End If

                               Next

                               For Each objSubFolder In objFolder.SubFolders

                                               Search(objSubFolder.Path)

                                               ' Files have been deleted, now see if

                                               ' the folder is empty.

                                               If (objSubFolder.Files.Count = 0) Then

                                                               objSubFolder.Delete True

                                               End If

                               Next

    loop

 

End Sub

 

 

Regards,

Balaram Reddy


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>