how to find all .jpg files in my computer using FileSystemObject, the output is to a txt file

How can I write a script to list all .jpg files in my computer by using FileSystemObject. The result should be put in a text file.
vbsnoobAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sirbountyConnect With a Mentor Commented:
This should do it..
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOut = objFSO.CreateTextFile ("C:\JPGReport.txt")
Set objFolder = objFSO.GetFolder("C:\")
 
Set colFiles = objFolder.Files
For Each objFile in colFiles
  If LCase(Right(objFile.Name, 3)) = "jpg" Then objOut.WriteLine file
Next
 
ScanFolders objFSO.GetFolder("C:\")
objOut.Close
wscript.quit
 
Sub ScanFolders(strFolder)
    For Each strSubFld in strFolder.SubFolders
        Set objFolder = objFSO.GetFolder(strSubFld.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
          If LCase(Right(objFile.Name, 3)) = "jpg" Then objOut.WriteLine file
        Next
        ScanFolders strFolder
    Next
End Sub

Open in new window

0
 
vbsnoobAuthor Commented:
thank you very much for ur speedy help!
0
 
hnasrCommented:
:) but you need to replace WriteLine file file with WriteLine file objFile
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sirbountyCommented:
oops... :^)
0
 
hnasrCommented:
:) but you need to replace WriteLine file with WriteLine objFile
0
 
t0t0Connect With a Mentor Commented:
Why not simply use a DOS command as in:

   dir /a-d /b /s c:\*.jpg >jpgfiles.txt

The results can be viewed by opening the JPGFILES.TXT in notepad etc...
0
 
aikimarkCommented:
I think the t0t0 suggestion is the best.
0
 
t0t0Commented:
aikimark

Thank you.
0
 
Justin_W_ChandlerCommented:
OBVIOUSLY, he has a reason for doing it in VB. I wouldn't be surprised if he's got an assignment for school that he's trying to get some help with.
0
 
t0t0Commented:
i'm good wih that!
0
All Courses

From novice to tech pro — start learning today.