Find the directory part (minus the filename) of a full path in access 97

前端 未结 10 542
太阳男子
太阳男子 2020-12-10 23:38

For various reasons, I\'m stuck in Access 97 and need to get only the path part of a full pathname.

For example, the name

c:\\whatever dir\\another d         


        
10条回答
  •  爱一瞬间的悲伤
    2020-12-11 00:21

    Try this function:

    Function FolderPath(FilePath As String) As String
    
        '--------------------------------------------------
        'Returns the folder path form the file path.
    
        'Written by:    Christos Samaras
        'Date:          06/11/2013
        '--------------------------------------------------
    
        Dim FileName As String
    
        With WorksheetFunction
            FileName = Mid(FilePath, .Find("*", .Substitute(FilePath, "\", "*", Len(FilePath) - _
                        Len(.Substitute(FilePath, "\", "")))) + 1, Len(FilePath))
        End With
    
        FolderPath = Left(FilePath, Len(FilePath) - Len(FileName) - 1)
    
    End Function

    If you don't want to remove the last backslash "\" at the end of the folder's path, change the last line with this:

    FolderPath = Left(FilePath, Len(FilePath) - Len(FileName))

    Example:

    FolderPath("C:\Users\Christos\Desktop\LAT Analysers Signal Correction\1\TP 14_03_2013_5.csv")
    

    gives:

    C:\Users\Christos\Desktop\LAT Analysers Signal Correction\1

    or

    C:\Users\Christos\Desktop\LAT Analysers Signal Correction\1\

    in the second case (note that there is a backslash at the end).

    I hope it helps...

提交回复
热议问题