VB Script to check if folder exist and delete on remote machines
Posted by Eswar Koneti on August 1st, 2012
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.
November 4th, 2012 at 12:56 AM
How would you go about specifying the folders to check if exist within a .txt file?
November 5th, 2012 at 2:12 PM
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