Results 1 to 3 of 3
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Finding recursive files (again)

    Hey guys,

    Im trying to count certain files that meet my criteria recursively.
    I have this function that does find files that way, but now they won't be found when my criteria is set.
    I am pretty sure that the function DID find found files that met my criteria, however it seemed it stopped working for some reason.



    So if i let the function look for files below the directory "Subdirectory" with a .pdf extension it will show howmany files there are.
    But, when i do the same and try to look for files with the current date into it (example as shown below) , it returns empty.

    I am struggeling with this badly, can someone please rescue me !

    Code:
    Option Compare Database
    
    
    
    
    Public Function RecursiveDir(colfiles As Collection, _
                                 strFolder As String, _
                                 strFileSpec As String, _
                                 bIncludeSubfolders As Boolean)
    
    
        Dim strTemp As String
        Dim colFolders As New Collection
        Dim vFolderName As Variant
    
    
        'Add files in strFolder matching strFileSpec to colFiles
        strFolder = TrailingSlash(strFolder)
        strTemp = Dir(strFolder & strFileSpec)
        Do While strTemp <> vbNullString
            colfiles.Add strFolder & strTemp
            strTemp = Dir
        Loop
    
    
        If bIncludeSubfolders Then
            'Fill colFolders with list of subdirectories of strFolder
            strTemp = Dir(strFolder, vbDirectory)
            Do While strTemp <> vbNullString
                If (strTemp <> ".") And (strTemp <> "..") Then
                    If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then
                        colFolders.Add strTemp
                    End If
                End If
                strTemp = Dir
            Loop
    
    
            'Call RecursiveDir for each subfolder in colFolders
            For Each vFolderName In colFolders
                Call RecursiveDir(colfiles, strFolder & vFolderName, strFileSpec, True)
            Next vFolderName
        End If
    
    
    End Function
    
    
    
    
    Public Function TrailingSlash(strFolder As String) As String
        If Len(strFolder) > 0 Then
            If Right(strFolder, 1) = "\" Then
                TrailingSlash = strFolder
            Else
                TrailingSlash = strFolder & "\"
            End If
        End If
    End Function
    Code:
    Dim colfiles As New Collection
    
    
    RecursiveDir colfiles, "I:\MyRootDIr\Subdirectory", "" & Format(Date, "dd/mm/yyy") & "*.pdf", True
    
    
    Dim vFile As Variant
    
    
    For Each vFile In colfiles
    Next vFile
    myControl = Colfiles.Count

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    It seems the code has problem with the date format.
    When i search like this :

    Code:
    RecursiveDir colfiles, "I:\MyRootDIr\Subdirectory", "*mytekst*.pdf", True


    It will find whatever is between the wildcards, am i dimensioning the date format wrong or ?

  3. #3
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Never mind i found the problem. the date of the files was mm/d/yyyy and im searching for mm/dd/yyyy
    What a difference a letter makes ... pfff

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Is a recursive query possible?
    By nigelbloomy in forum Queries
    Replies: 3
    Last Post: 09-10-2015, 04:04 PM
  2. Need help with recursive design
    By frankos72 in forum Database Design
    Replies: 12
    Last Post: 10-09-2013, 08:04 AM
  3. finding Access 2003 files in Access 2007
    By philetus in forum Access
    Replies: 1
    Last Post: 05-25-2012, 01:34 PM
  4. Recursive Tables!
    By Rawb in forum Database Design
    Replies: 1
    Last Post: 01-26-2011, 02:46 PM
  5. FileSearch object not finding files
    By tdalber in forum Programming
    Replies: 3
    Last Post: 05-14-2009, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums