In B4A I use your example code to change a folder name:
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
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
NavControl.ShowPage(Page1)
Page1.RootPanel.LoadLayout("1")
File.WriteString(File.DirDocuments, "1.txt", "Sdfsdf")
Dim no As NativeObject = Me
Log(no.RunMethod("renameFile::", Array (File.Combine(File.DirDocuments, "1.txt"), _
File.Combine(File.DirDocuments, "111.txt"))).AsBoolean)
Log(File.ListFiles(File.DirDocuments))
End Sub
#if objc
- (BOOL)renameFile: (NSString*)source :(NSString*)target {
return [[NSFileManager defaultManager] moveItemAtPath:source toPath:target error:nil];
}
#end if
I see in the example you typed 1.txt and 111.txt but does it work for directories also ?
If so, on the footprint of the B4A example I could write:
B4X:
Sub RenameFolder(Parent As String, CurrentFolder As String, NewFolder)
Dim args(2) As String
args(0) = File.Combine(Parent, CurrentFolder)
args(1) = File.Combine(Parent, NewFolder)
Dim no As NativeObject = Me
no.RunMethod("renameFile::", Array( args(0), args(1))).AsBoolean
Return
End Sub
#if objc
- (BOOL)renameFile: (NSString*)source :(NSString*)target {
return [[NSFileManager defaultManager] moveItemAtPath:source toPath:target error:nil];
}#end if