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?
 
sirbountyCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
sirbountyCommented:
oops... :^)
0
 
hnasrCommented:
:) but you need to replace WriteLine file with WriteLine objFile
0
 
t0t0Commented:
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
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.

All Courses

From novice to tech pro — start learning today.