Wednesday, July 18, 2007

Get file names from a directory

If you want get or print file names from a certain directory, then you can use following code.


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

Comments: Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?