Close Menu
    Facebook X (Twitter) Instagram
    Sunday, October 12
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»Scripting»VB Script to check if folder exist and delete on remote machines

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

    Eswar KonetiBy Eswar KonetiAugust 01, 10:34 am1 Min Read Scripting 2,585 Views
    Share
    Facebook Twitter LinkedIn Reddit

    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.

    delete files from remote computer vb script VB Script vb script check if folder exist on remote computer
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Application Deployment with Hybrid Joined Requirement Rules in Intune

    October 06, 8:59 pm

    Troubleshooting Windows KMS Activation Issues with SCCM scripts feature

    September 09, 11:07 pm

    Migrating Windows Update Workloads from SCCM to Intune: How to Verify Management Tool

    August 23, 9:55 pm

    2 Comments

    1. thirdchild on November 4, 2012 12:56 AM

      How would you go about specifying the folders to check if exist within a .txt file?

      Reply
      • Eswar Koneti on November 5, 2012 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

        Reply

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2025 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.