+ Reply to Thread
Results 1 to 2 of 2

Search for file in directory

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2005
    Posts
    24

    Search for file in directory

    I have a function that will search for a csv file in a directory.

     Set fs = Application.FileSearch
        With fs
          .LookIn = DefaultFolder
          .Filename = "FGIVAL*.csv"
          If .Execute > 0 Then
             'Some code
          End If
        End With
    In the directory, I have 2 files, named "FGIVAL_2008-02-11.csv" and "WFGIVAL_2008-02-11.csv". By using the above search function, it will returns both file name.

    But I dont expect the file name starts with "W" to be in the search result. I really dunno what is going on here.

    Anyone please advice.

    Thanks.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    ryanlcs,

    Check out the following code that will run on any *.csv file containing "FGIVAL" within its' name.

    Set fs = Application.FileSearch
        
        With fs
          .LookIn = DefaultFolder
          .Filename = "*.csv"
          
          If .Execute > 0 Then
            
            For i = 1 To .FoundFiles.Count
                If InStr(.FoundFiles(i), "FGIVAL") > 0 Then
                'Some code
                End If
            Next i
            
          End If
          
        End With
    HTH

    Robert

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1