PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Get Filename from Filepath
This function returns the filename including the file extension, when passed the full filepath. The function searches for the leading backslash to determine to start of the filename. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
Function GetFileName(ScanString as String) As String

'*******************************************************
'<DESC>		Retrieves FileName from full
'		directory path</DESC>
'<RETURN>	FileName Only
'			</RETURN>
'<ACCESS>	Public
'<ARGS>		FullPath: 
'			Full Filepath incl. Filename
'				</ARGS>
'<USAGE>	If GetFileName("c:\temp\myDoc.txt")
'				</USAGE>
'*******************************************************

    Dim intPos as Integer
    Dim intPosSave as Integer

    intPos = 1
    Do
        intPos = InStr(intPos, ScanString, "\")
        If intPos = 0 Then
            Exit Do
        Else
            intPos = intPos + 1
            intPosSave = intPos - 1
        End If
    Loop
    GetFileName = Trim$(Mid$(ScanString, intPosSave + 1))

End Function
    
 

Top of Page

Legal Notice

Ken Howe 2011