VB File System Object

Posted on 2003-03-10
Medium Priority
Last Modified: 2010-04-07


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!!!!

Question by:merlin_vb
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

Accepted Solution

graham_charles earned 140 total points
ID: 8101905
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 >.

LVL 26

Expert Comment

ID: 8102484
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

Author Comment

ID: 8102974
Dear Mr.graham_charles ,

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


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 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