Is there a way for DIR(path) in VBA to handle strings longer than 260?

后端 未结 5 783
渐次进展
渐次进展 2020-12-06 06:54

Given the following snippet:

Dim s As String: s = \"S:\\vic\\bla\\[..insert more here..]\\data.xml\"
Debug.Print Len(s)
Debug.Print Dir(s)

5条回答
  •  一整个雨季
    2020-12-06 07:09

    I have no means of testing this, so all you have is a few rough notes on a possible approach.

    ''Reference: Windows Script Host Object Model
    Dim fs As New FileSystemObject
    Dim fl As Folder
    Dim fl2 As Folder
    
    Set fl = fs.GetFolder("Z:\Docs\test\ThisIsInOrderToCreate\ALongFilePath\")
    Set fl2 = fl.SubFolders("WithASubFolder")
    Debug.Print fl2.ShortPath
    For Each File In fl2.Files
        If File.Name = "file.txt" Then
            Debug.Print "Found"
        End If
    Next
    
    ''May be possible
    a = Dir(fl.ShortPath & "\file.*")
    

    Also, regarding comment above:

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.MapNetworkDrive "L:", "\\mydrive\share"
    ''Important to destroy when you are finished
    Set WshNetwork = Nothing
    

提交回复
热议问题