VB File System Object


i want search the ex1.jpg and also display the all images in the corrosponding(000333) directory.
i am using file system object.

My code is below. This code searching only the 0001111 directory.Its not iterating the other dorectorys.

The application path is   archival

Set fso = CreateObject("Scripting.FileSystemObject")
Set mainfolder = fso.GetFolder("C:\archival")
'MsgBox mainfolder.name
Set foldercollections = mainfolder.SubFolders
For Each temp In foldercollections
    FolderName = temp.name
    'MsgBox FolderName
     Set tmpFolder = fso.GetFolder(FolderName)
     Set insideFolder = tmpFolder.Files
        For Each findFIles In insideFolder
            'MsgBox findFIles.name
            If findFIles.name = "ex1.jpg" Then
                For Each findtemp In insideFolder
                    'MsgBox findtemp.name
            End If

if anyone knows please help me . Advanced thanks!!!!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You'll have an easier time if you write a recursive function. Take a look at sample listing 3 at < http://www.fawcette.com/vsm/2002_08/magazine/columns/gettingstarted/default_pf.asp >; that should get you what you need. Another good example is at  < http://www.microbion.co.uk/developers/fso.htm >.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Try this

Option Explicit

Private Sub Command1_Click()
FileAttribute "c:\temp", "Account.vbp"
End Sub

Public Sub FileAttribute(ByVal FilePath As String, ByVal FileName As String)
    Dim fso
    Dim folder
    Dim f
    Dim Files
    Dim File
    Dim SubFolders
    Dim SubFolder
    On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder(FilePath)
    Set SubFolders = folder.SubFolders
    If SubFolders.Count <> 0 Then
        For Each SubFolder In SubFolders
            FileAttribute SubFolder, FileName
    End If
    Set Files = folder.Files
    If Files.Count <> 0 Then
        For Each File In Files
            Set f = fso.GetFile(File)
            If (f.Name = FileName) Then
                MsgBox "Find file " & FilePath & "\" & FileName
            End If
            Set f = Nothing
    End If
End Sub
merlin_vbAuthor Commented:
Dear Mr.graham_charles ,

                         Thanks for your great help.
I am working on it.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.