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

Get Directory Name from Filepath
This function returns the full directory, when passed the full filepath. The function searches for the leading backslash to determine the end of the directory. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
Function GetDirName(ScanString As String) As String

'<DESC>		Retrieves a directory path from full path 
'		(ie filepath & filename)</DESC>
'<RETURN>	Boolean:
'			<LI> Dir Path as String
'			</RETURN>
'<ACCESS>	Public
'<ARGS>		FullPath: Full Filepath incl. Filename
'		</ARGS>
'<USAGE>	DirPath$ = ("c:/winnt/winhlp32.exe")
'				</USAGE>

    Dim intPos As Integer
    Dim intPosSave As Integer
    intPos = 1
        intPos = InStr(intPos, ScanString, "\")
        If intPos = 0 Then
            Exit Do
            intPos = intPos + 1
            intPosSave = intPos - 1
        End If
    GetDirName = Left$(ScanString, intPosSave)

End Function

Top of Page

Legal Notice

Ken Howe 2011