VB Script to check if folder exist and delete on remote machines

Script to check files on remote computer and delete them if they are available.

ON ERROR RESUME NEXT

Set objfso = CreateObject ("Scripting.FileSystemObject")
Set computerList = objfso.OpenTextFile ("C:\Scripts\computerList.txt", 1)
Set outputList = objfso.OpenTextFile ("C:\Scripts\outputList.txt", 2, True)

Do While Not computerList.AtEndOfStream

strComputer = computerList.ReadLine
If objFSO.FolderExists("\\" & strComputer & "\F$\oldfiles") Then
Set strFolderPath = objFSO.GetFolder("\\" & strComputer & "\f$\oldfiles")

objFSO.DeleteFolder strFolderPath, True
outputList.WriteLine strComputer & vbTab & "oldfiles folder deleted"

Else

outputList.WriteLine strComputer & vbTab & "Oldfiles folder does not exist"

End If

loop

Change the Bold letters as necessary.

2 Responses to "VB Script to check if folder exist and delete on remote machines"

    1. yes you can.
      Try something below :

      ON ERROR RESUME NEXT

      Set objfso = CreateObject ("Scripting.FileSystemObject")

      Set files = objfso.OpenTextFile ("C:\files.txt", 1)
      Set outputList1 = objfso.OpenTextFile ("C:\results.txt", 2, True)

      Do While Not files.AtEndOfStream

      filename = files.ReadLine

      If objFSO.fileExists("\\" & strComputer & "\E$\Ent") Then

      outputList1.WriteLine strComputer & vbTab & "Folder Exist"

      Else

      outputList1.WriteLine strComputer & vbTab & "No File avilable"

      End If

      loop

      Reply

Leave a Reply