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

前端 未结 10 521
太阳男子
太阳男子 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:17

    Use these codes and enjoy it.

    Public Function GetDirectoryName(ByVal source As String) As String()
    Dim fso, oFolder, oSubfolder, oFile, queue As Collection
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set queue = New Collection
    
    Dim source_file() As String
    Dim i As Integer        
    
    queue.Add fso.GetFolder(source) 'obviously replace
    
    Do While queue.Count > 0
        Set oFolder = queue(1)
        queue.Remove 1 'dequeue
        '...insert any folder processing code here...
        For Each oSubfolder In oFolder.SubFolders
            queue.Add oSubfolder 'enqueue
        Next oSubfolder
        For Each oFile In oFolder.Files
            '...insert any file processing code here...
            'Debug.Print oFile
            i = i + 1
            ReDim Preserve source_file(i)
            source_file(i) = oFile
        Next oFile
    Loop
    GetDirectoryName = source_file
    End Function
    

    And here you can call function:

    Sub test()
    Dim s
    For Each s In GetDirectoryName("C:\New folder")
    Debug.Print s
    Next
    End Sub
    

提交回复
热议问题