Solved

vbscript search for all files given the files extension

Posted on 2009-05-20
2
450 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

22 Experts available now in Live!

Get 1:1 Help Now