While working on files and folders, many a time I come across a situation where I want the list of all filenames in a specific folder or directory. I tried out a code that helps me a lot. – Selva V Pasupathy
Sub GetFileNames()
Dim sPath As String, sFileNm As String
sPath = “C:DW”
‘You can also use Application.GetOpenFilename to get a file name from a folder,
‘and then extract the Directory name from that string
‘You can also use filters with GetOpenFilenam such as *.txt, see Help on this topic
sFileNm = Dir(sPath, vbNormal) ‘Get the first file from the specified directory
‘Start a loop
Do While sFileNm <> “”
‘If the file has a dbf extension then print the file name
If Right(sFileNm, 3) = “dbf” Then
Debug.Print sFileNm
End If
sFileNm = Dir
Loop
End Sub