Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vbscript search for all files given the files extension

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

837 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