Results 1 to 2 of 2
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670

    Ignore Folders In Recursive File Search


    I found this recursive file search syntax, and I was wondering if there was a way to set folders to be ignored. For example, ignore the folder R:\admin or R:\administrator
    Code:
    Option Compare Database
    Option Explicit
    
    Sub ScanTablesWriteDataToText()
    Dim Fileout AsObject
    Dim fso AsObject
    Dim objFSO AsObject
    Dim accapp As Access.Application
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim colFiles As Collection
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Dim objRegExp AsObject
    Set objRegExp = CreateObject("VBScript.RegExp")
    objRegExp.Pattern =".jpg"
    objRegExp.IgnoreCase =True
    
    Set colFiles =New Collection
    
    RecursiveFileSearch "R:\", objRegExp, colFiles, objFSO
    
    ForEach f In colFiles
        'do something
    Next
    Set objFSO =Nothing
    Set objRegExp =Nothing
    
    EndSub
    Sub RecursiveFileSearch(ByVal targetFolder AsString,ByRef objRegExp AsObject, _
                    ByRef matchedFiles As Collection,ByRef objFSO AsObject)
    
    Dim objFolder AsObject
    Dim objFile AsObject
    Dim objSubFolders AsObject
    Set objFolder = objFSO.GetFolder(targetFolder)
    ForEach objFile In objFolder.files
        If objRegExp.test(objFile)Then
            matchedFiles.Add (objFile)
        EndIf
    Next
    Set objSubFolders = objFolder.Subfolders
    ForEach objSubfolder In objSubFolders
        RecursiveFileSearch objSubfolder, objRegExp, matchedFiles, objFSO
    Next
    Set objFolder =Nothing
    Set objFile =Nothing
    Set objSubFolders =Nothing
    
    EndSub
    
    
    Link http://vba-tutorial.com/recursive-di...x-file-search/

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    If you know the folder names, put them in a table.
    Then in your processing adjust your set up to exclude values in your table.

    See this link on Excluding values for more info

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

Similar Threads

  1. Replies: 2
    Last Post: 05-24-2016, 04:54 PM
  2. Replies: 13
    Last Post: 07-05-2012, 10:33 AM
  3. Search to ignore null fields
    By tommy93 in forum Queries
    Replies: 10
    Last Post: 02-07-2012, 10:58 AM
  4. Search for associated folders in file dialog box
    By john_billau in forum Programming
    Replies: 1
    Last Post: 01-27-2012, 03:48 PM
  5. Remove/Ignore beginning of text file on import
    By Insyderznf in forum Import/Export Data
    Replies: 9
    Last Post: 10-24-2011, 04:56 PM

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