Wish File.Rename and File.Delete(into trashcan)

stevel05

Expert
Licensed User
OK, the RenameTo in the Library looks like it only moves in the same directory. This one will work anywhere (That you have the correct access rights to)

B4X:
'Renames the file denoted by this pathname.
Public Sub RenameTo(DirName As String, FileName As String, NewDirName As String, NewFileName As String) As Boolean
    Dim Source As JavaObject
    Source.InitializeNewInstance("java.io.File",Array(DirName,FileName))
    Dim Dest As JavaObject
    Dest.InitializeNewInstance("java.io.File",Array(NewDirName,NewFileName))
    Return Source.RunMethod("renameTo",Array As Object(Dest))
End Sub
 

Star-Dust

Expert
Licensed User
B4X:
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
 
Top