Andris
Andris

Reputation: 13

Is there an easy way to rename a directory in Basic4Android?

I would like to rename a directory that I created on the SD card and thought I could easily do that through the File object (something like File.Rename). However, I don't see something that easy. Do I have to copy all of the directory structure to a new directory with the new name, delete all the files in the old directory, and then delete the old directory to do this? Or is there an easy way that I don't know about?

Upvotes: 1

Views: 767

Answers (1)

Erel
Erel

Reputation: 1802

You can use Phone.Shell to run the 'mv' command:

Sub Activity_Create(FirstTime As Boolean)
    RenameFolder(File.DirRootExternal, "test1", "test2")
End Sub

Sub RenameFolder(Parent As String, CurrentFolder As String, NewFolder)
    Dim p As Phone
    Dim args(2) As String
    args(0) = File.Combine(Parent, CurrentFolder)
    args(1) = File.Combine(Parent, NewFolder)
    p.Shell("mv", args, Null, Null)
End Sub

Upvotes: 2

Related Questions