FILTER by .csv pattern

User avatar
sal21
PlatinumLounger
Posts: 4605
Joined: 26 Apr 2010, 17:36

FILTER by .csv pattern

Post by sal21 »

my code:

Code: Select all

Public Sub LoopAllFilesInFolder()

    Dim folderName As String
    Dim FSOLibrary As Object
    Dim FSOFolder As Object
    Dim FSOFile As Object, NOMEFILE As String

    folderName = "C:\Lavori_Vb6\MAPPA_ITALIA\FILES\PR_ZIP\"

    Set FSOLibrary = CreateObject("Scripting.FileSystemObject")
    Set FSOFolder = FSOLibrary.GetFolder(folderName)

    For Each FSOFile In FSOFolder.Files

        NOMEFILE = FSOFile.Name

    Next

    Set FSOLibrary = Nothing
    Set FSOFolder = Nothing

End Sub
i nned to filter only a file with pattern .csv, how to?

User avatar
HansV
Administrator
Posts: 80207
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: FILTER by .csv pattern

Post by HansV »

Code: Select all

Public Sub LoopAllFilesInFolder()

    Dim folderName As String
    Dim FSOLibrary As Object
    Dim FSOFolder As Object
    Dim FSOFile As Object, NOMEFILE As String

    folderName = "C:\Lavori_Vb6\MAPPA_ITALIA\FILES\PR_ZIP\"

    Set FSOLibrary = CreateObject("Scripting.FileSystemObject")
    Set FSOFolder = FSOLibrary.GetFolder(folderName)

    For Each FSOFile In FSOFolder.Files
        ' Look at .csv files only
        If UCase(Right(FSOFile, 4)) = ".CSV" Then
            NOMEFILE = FSOFile.Name
        End If
    Next FSOFile

    Set FSOLibrary = Nothing
    Set FSOFolder = Nothing

End Sub
Best wishes,
Hans