I found this code, which only lists the available drives on PC, but not their names. How to list names also?
I need a solution only for PC in this case. Is there a way to get the drive names from the example below?
B4X:
For Each drive As String In ListRoots
Log(drive)
Next
Sub ListRoots As List
Dim jo As JavaObject
Dim o() As Object = jo.InitializeStatic("java.io.File").RunMethod("listRoots", Null)
Return o
End Sub
Dim fsv As JavaObject
fsv.InitializeStatic("javax.swing.filechooser.FileSystemView")
For Each drive As Object In ListRoots
Log(drive)
Log(fsv.RunMethodJO("getFileSystemView",Null).RunMethod("getSystemDisplayName",Array(drive)))
Next
@Daestrum Nice solution. I put it in a source code. Feel free to update it as you please. It would be nice to add more info as well, so if you know how to do it throw it in there as well in the example. Drive types would be nice and perhaps available space too. Cheers
@Daestrum Nice solution. I put it in a source code. Feel free to update it as you please. It would be nice to add more info as well, so if you know how to do it throw it in there as well in the example. Drive types would be nice and perhaps available space too. Cheers
@inakigarm Great addition indeed. I have a follow up question to Daestrums post. I tried to get the lenght of the drive name so I can use substring and substract the lenght by -3 to remove the "C:\" etc at the end, since I am adding it like this
So how can I get the complete drive name and the lenght at the same time. The problem is that it is an object, and that's why the Substring method does not work.
Hopefully the object can be converted to string in the same loop to get the lenght of the drivename.
Dim dr As String = fsv.RunMethodJO("getFileSystemView",Null).RunMethod("getSystemDisplayName",Array(drive))
Log("Display Name : "&dr.SubString2(dr.LastIndexOf("(")+1,dr.Length-1)&"\ "&dr.SubString2(0,dr.LastIndexOf("(")-1))
@Daestrum Nice. However I solved it another way since I am using the FloatingMenu Class by Steve05.
This is how it's done
FloatingMenu Class
B4X:
'Create and return a TextMenuItem Object #2
Public Sub MenuText2(Text As String) As FMItemTextClass
Dim MI As FMItemTextClass
If Text.Length >= 8 Then
MI.Initialize(Me,"MI",Text.SubString2(0,Text.Length-4))
Else
MI.Initialize(Me,"MI",Text & " [CD-Rom/DVD/Virtual Drive]")
End If
'Add a style to the MenuItem
FMUtils.AsJO(MI.ASJavaObject).RunMethodJO("getStyleClass",Null).RunMethod("addAll",Array(Array As String("cmenu","menutext")))
Return MI
End Sub