Solved

vbscript search for all files given the files extension

Posted on 2009-05-20
2
451 Views
Last Modified: 2012-05-07
I'm trying to create a vbscript to search for all files given the files extension but got bit stuck when im trying to create a sub function to search for the files in  the subfolders.

I wanted to create a sub function with a loop inside so it continue on to find the subfolders after it finish scanning the targeted folder
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objOut = objFSO.CreateTextFile ("C:\scanreport.txt")

Set objFolder = objFSO.GetFolder("c:\backup")

Set colFiles = objFolder.Files
 

For Each objFile in colFiles

  If LCase(Right(objFile.Name, 3)) = "txt" Then 

		objOut.Write objFile.Name

		objOut.Write objFile.Path

		objOut.WriteLine

  End If

Next
 

objOut.Close

wscript.Quit

Open in new window

0
Comment
Question by:vbsnoob
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 24430686
Dim objFSO, objOut, objFolder

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOut = objFSO.CreateTextFile ("C:\scanreport.txt", True)
Set objFolder = objFSO.GetFolder("c:\backup")

ListTheFiles objFolder, objOut

objOut.Close
Set objOut = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

Sub ListTheFiles(UseFolder, UseTS)

    Dim objSF, objFile

    For Each objFile In UseFolder.Files
        If LCase(Right(objFile.Name, 3)) = "txt" Then objOut.WriteLine objFile.Path
    Next

    For Each objSF In UseFolder.SubFolders
        ListTheFiles objSF, UseTS
    Next

    Set objFile = Nothing
    Set objSF = Nothing

End Sub
0
 

Author Closing Comment

by:vbsnoob
ID: 31583416
thank you for ur help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

932 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

13 Experts available now in Live!

Get 1:1 Help Now