B4J Question URI for networked drives on Windows

Didier99

Member
Licensed User
One of the things that drives (pun intended) me nuts with Windows is the use of drive letters as shortcuts to network path.
I understand the convenience within the scope of a single user, but since there is no enforcement that all users on a network use the same drive letter for a given resource, it's very hard to reliably share resource locations across users.
The point is that when I select a file, I would like to get the absolute network path as URI instead of a relative path to a drive letter.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think that your best option is to run "net use" with jShell:
B4X:
Private Sub Button1_Click
    Wait For (NetUse) Complete (StdOut As String)
End Sub

Private Sub NetUse As ResumableSub
    Dim s As Shell
    s.Initialize("s", "net", Array("use"))
    s.Run(60000)
    Wait For (s) s_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log($"ExitCode: ${ExitCode}, StdOut: ${StdOut}, StdErr: ${StdOut}"$)
    Return StdOut
End Sub

I don't have any mapped network drive here, so can't help you with parsing. Post the output if need assistance with this.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Supplementary the URI of parsing the StdOut
B4X:
Private Sub Button1_Click
    Wait For (NetUse) Complete (StdOut As String)
    Dim Matcher1 As Matcher
    Matcher1 = Regex.Matcher("\\\\[A-Za-z0-9-]+\\", StdOut)
    Do While Matcher1.Find
        Log("URI: " & Matcher1.Match)
    Loop
End Sub
 
Upvote 0
Top