• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

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

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.
1 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now