(Solved) – How to get the filename with csv extension

  • by
(solved)-–-how-to-get-the-filename-with-csv-extension

im trying to get file name with csv extension , but when i try to debug.print it always print the .csv file and the .txt file

im search the file in the folder and subfolder

heres the code

Sub LoopAllSubFolders(ByVal folderPath As String)

Dim fileName As String
Dim fullFilePath As String
Dim numFolders As Long
Dim folders() As String
Dim i As Long

If Right(folderPath, 1) <> "" Then folderPath = folderPath & ""
fileName = Dir(folderPath & "*.*", vbDirectory)

While Len(fileName) <> 0

    If Left(fileName, 1) <> "." Then

        fullFilePath = folderPath & fileName

        If (GetAttr(fullFilePath) And vbDirectory And Not (fullFilePath Like "*csv*")) = vbDirectory Then
            ReDim Preserve folders(0 To numFolders) As String
            folders(numFolders) = fullFilePath
            numFolders = numFolders   1
        Else
            'Insert the actions to be performed on each file
            'This example will print the full file path to the immediate window
            Debug.Print folderPath & fileName
        End If

    End If

    fileName = Dir()

Wend

For i = 0 To numFolders - 1

    LoopAllSubFolders folders(i)

Next i

End Sub

The code i get from website and i add not like "*csv*"

perhaps someone can correcting the code,

thankyou

Leave a Reply

Your email address will not be published. Required fields are marked *