B4J Question How to rename a USB Stick

johnmie

Active Member
Licensed User
Longtime User
Hi there,
for building a DB catalogue of my 30+ USB sticks to better remember where to find old stuff, I would like to rename some of the display names (other than manually in properties of the explorer).
I started with Erel's files treeview and found RunMethod("getSystemDisplayName"... in the forum but not the corresponding set, modify or create the name.
This is essential to avoid confusion and duplicates. Alternatively I could live with a serial number if such a thing existed

Also it would be nice to show the sizes of each folder so that I would not have to loop through the entire file list. The only fx command I found just tells me the amount of unused space on stick. There must be a fx method for that, but how to find and implement it?

Any help will be greatly appreciated and thanks in advance,
johnmie
 
Solution
B4X:
Private Sub RenameDrive (Drive As String, NewName As String) As ResumableSub
    Dim shl As Shell
    shl.Initialize("shl", File.Combine(GetEnvironmentVariable("windir", "N/A"), "System32\label.exe"), Array(Drive, NewName))
    shl.Run(-1)
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
    Log(StdErr)
    Return Success And ExitCode = 0
End Sub

Usage:
B4X:
Wait For (RenameDrive("H:", "Test3")) Complete (Success As Boolean)
Log("renamed successfully? " & Success)

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Private Sub RenameDrive (Drive As String, NewName As String) As ResumableSub
    Dim shl As Shell
    shl.Initialize("shl", File.Combine(GetEnvironmentVariable("windir", "N/A"), "System32\label.exe"), Array(Drive, NewName))
    shl.Run(-1)
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
    Log(StdErr)
    Return Success And ExitCode = 0
End Sub

Usage:
B4X:
Wait For (RenameDrive("H:", "Test3")) Complete (Success As Boolean)
Log("renamed successfully? " & Success)
 
Upvote 0
Solution

johnmie

Active Member
Licensed User
Longtime User
B4X:
Private Sub RenameDrive (Drive As String, NewName As String) As ResumableSub
    Dim shl As Shell
    shl.Initialize("shl", File.Combine(GetEnvironmentVariable("windir", "N/A"), "System32\label.exe"), Array(Drive, NewName))
    shl.Run(-1)
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
    Log(StdErr)
    Return Success And ExitCode = 0
End Sub

Usage:
B4X:
Wait For (RenameDrive("H:", "Test3")) Complete (Success As Boolean)
Log("renamed successfully? " & Success)
This is great and works beautifully.
Thank you very much, Erel,
john
 
Upvote 0
Top