B4J Code Snippet B4J File Utils

SubName: GetVolumeLabel

Description: Returns the name of a volume (for example: 'RECOVERY').

Depends On: JavaObject

B4X:
Sub GetVolumeLabel(Path As String) As String
    Dim JO As JavaObject
    Dim Dir As JavaObject
    JO = JO.InitializeStatic("javax.swing.filechooser.FileSystemView").RunMethod("getFileSystemView", Null)
    Dir.InitializeNewInstance("java.io.File", Array As Object(Path))
    Return JO.RunMethod("getSystemDisplayName", Array As Object(Dir))
End Sub

Example:
B4X:
GetVolumeLabel("C:\") 'Returns "Local Disk (C:\)" on my Windows machine.

Tags: Volume Label

Notes: Has only been tested on Windows, unsure if it will work on Mac or Linux.
 

sonicmayne

Member
Licensed User
Longtime User
SubName: GetVolumeType

Description: Returns the type of a volume (for example: 'Local Disk', 'Removable Disk' and so on)

Depends On: JavaObject

B4X:
Public Sub GetVolumeType(Path As String) As String
    Dim JO As JavaObject
    Dim Dir As JavaObject
    JO = JO.InitializeStatic("javax.swing.filechooser.FileSystemView").RunMethod("getFileSystemView", Null)
    Dir.InitializeNewInstance("java.io.File", Array As Object(Path))
    Return JO.RunMethod("getSystemTypeDescription", Array As Object(Dir))  
End Sub

Example:
B4X:
GetVolumeType("E:\") 'Returns CD Drive on my machine

Tags: Volume Type

Notes: Has only been tested on Windows, unsure if it will work on Mac or Linux.
 

sonicmayne

Member
Licensed User
Longtime User
SubName: GetMyDocuments

Description: Returns the default directory for the user to save their files to.

Depends On: JavaObject

B4X:
Public Sub GetMyDocuments As String
    Dim JO As JavaObject
    Return JO.InitializeStatic("javax.swing.filechooser.FileSystemView").RunMethodJO("getFileSystemView", Null).RunMethod("getDefaultDirectory", Null)   
End Sub

Tags: My Documents, User Directory

Notes: Has only been tested on Windows, unsure if it will work on Mac or Linux.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…