B4J Question Finding a Windows drive by label

Brian Dean

Well-Known Member
Licensed User
Longtime User
Is there a way to retrieve the volume names (drive labels) on a Windows system?

Specifically, I want to discover if a specific USB stick is present by scanning for its name. I already know (through the forum) how to get a list of the drive letters available (C:\, D:\ etc) but I cannot find anything on volume names.

I think that it can be done using this java method ...
Java:
FileSystemView.getFileSystemView().getSystemDisplayName (f)
... but I don't know how to write a javaObject to execute this.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
... but I don't know how to write a javaObject to execute this.
start using the search; there are examples available which do get the 1st two of this (FileSystemView.getFileSystemView())
Add a call to get the SystemDisplayName

B4X:
Sub FindDisplayName(f As String) As String
    If DetectOS = "windows" Then
        Dim jo As JavaObject
        Dim fs As JavaObject = jo.InitializeStatic("javax.swing.filechooser.FileSystemView").RunMethod("getFileSystemView", Null) ' known
        Dim fsfile As JavaObject = fs.RunMethod("createFileObject", Array(f))  ' new
        Return fs.RunMethod("getSystemDisplayName", Array(fsfile)) ' new
    Else
        Return ""
    End If
End Sub
B4X:
    Log(FindDisplayName("E:\"))
results in
Entwicklung (E:)
prove

gtspecII003.png


Reference:
 
Last edited:
Upvote 0
Top