VBScript that will run through several folder trees and run this script on each folder in the tree

Posted on 2006-06-08
Last Modified: 2012-06-27
I am having a difficult time creating a script that will run through various folder trees and run the following script on every document with in the folder.

'Set Type of Files To Act Upon
DocumentType="Microsoft PowerPoint Presentation"

'Generate Objects for Filesystem, Folder, and Files within the current folder
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set FileSysFolder = FileSysObj.GetFolder(FileSysObj.GetAbsolutePathName("folder path"))
Set FileSysFiles = FileSysFolder.Files

Set PowerPoint = CreateObject("PowerPoint.Application")
PowerPoint.Visible = False

'Loop through each File In the Folder
For Each ObjFile in FileSysFiles
  If (objFile.Type = DocumentType) Then
     Pres_Name = FileSysFolder & "\" & objFile.Name
     PowerPoint.Presentations(Pres_Name).BuiltInDocumentProperties("Title").Value = PowerPoint.Presentations(Pres_Name).Name
  End If


These folders are for archived documents, so they go from year, month, and day.  I have no idea how to create a script that will perform the script on every folder.
Question by:jlakor
    1 Comment
    LVL 44

    Accepted Solution

    Hi jlakor,

    you'll find a recursive showfolders function here for that purpose

    ShowSubfolders objFSO.GetFolder(objStartFolder)

    Sub ShowSubFolders(Folder)
        For Each Subfolder in Folder.SubFolders
            Wscript.Echo Subfolder.Path
            Set objFolder = objFSO.GetFolder(Subfolder.Path)
            Set colFiles = objFolder.Files
            For Each objFile in colFiles
                Wscript.Echo objFile.Name
            ShowSubFolders Subfolder
    End Sub

    it loops through all files in the startfolder then goes below and does the same for all subfolders
    share what you know, learn what you don't

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Title # Comments Views Activity
    Help with my python script 6 135
    Convert Jpg /PNG To GIF 5 78
    sameEnds challenge 3 80
    has12 challenge 13 52
    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now