Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

VB File System Object


C:\Archival\0001111\0002222\000333\ex1.jpg
                       exe2.pdf
                       exe3.jpg
                       exrdoc.doc

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
                    findtemp.Delete
                Next
            End If
           
        Next
Next


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

Thanks,
Merlin
0
merlin_vb
Asked:
merlin_vb
1 Solution
 
graham_charlesCommented:
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 >.

g.
0
 
EDDYKTCommented:
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
        Next
    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
        Next
    End If
End Sub
0
 
merlin_vbAuthor Commented:
Dear Mr.graham_charles ,

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

Thanks,
Merlin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now