Help with Array search script

Fyr

Active Member
Joined
Jan 20, 2009
Messages
375
I have a script below that goes into a specified directory and searches for 2 file extensions.
I know it's not setup correctly, I am needing help to get the script working correctly.

thanks for taking a look!


Code:
Option Explicit
Public TotalPathFiles As String
Public FSO As Object
Sub SearchFileCount()
Dim FilesInPath As String
Dim oFolder As Object
Dim oFiles As Object
Dim oFile As Object
Dim strExt(2) As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder("C:\TestCase")
Set oFiles = oFolder.Files
strExt(0) = "F01"
strExt(1) = "f01"
FilesInPath = 0
For Each oFile In oFolder.Files
[COLOR=red][B]   If Right(oFile, 3) = UBound(Filter(strExt, oFile)) Then[/B][/COLOR]
[B][COLOR=red]       FilesInPath = FilesInPath + 1[/COLOR][/B]
[B][COLOR=red]   End If[/COLOR][/B]
Next
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Maybe something like:

Rich (BB code):
Sub SearchFileCount()
Dim FSO As Object
    
Dim FilesInPath As String
Dim oFolder As Object
Dim oFiles As Object
Dim oFile As Object
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = FSO.GetFolder("C:\TestCase\")
    
    Set oFiles = oFolder.Files
    
    FilesInPath = 0
    
    For Each oFile In oFolder.Files
        If LCase(Mid(oFile.Name, InStrRev(oFile.Name, ".") + 1)) = "f01" Then
            FilesInPath = FilesInPath + 1
        End If
    Next
    
    MsgBox FilesInPath
End Sub
 
Upvote 0
PS - I forgot to mention, just by the looks of your current, FilesInPath would be returning a number as a string, but then it doesn't do anything with the results. You may wish to mention where we'd like FilesInPath to ultimately end up, such as part of a msg to the user or ??? You may wish to turn the sub into a short function that returns the number (I would probably leave it a legit number, and convert later if needed).
 
Upvote 0
You are most welcome and glad that helped:)
 
Upvote 0

Forum statistics

Threads
1,225,072
Messages
6,182,698
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top