How do you rename a file?

Danamo

Member
Licensed User
Hi, I can see this is an old thread, But is there now a command to rename files? Its 2014 now :)
It's now 2017 - going on 2018!

Renaming a file is such a standard file mangement function supported by every programming language going as far back in antiquity as TRSDOS, FORTRAN and COBOL that it seems odd to me that any modern programming language wouldn't have it. Especially in this era where file storage capacity supports vast numbers of files and files are ubiquitous to almost any application.

Neither Steve nor Margret's code solutions in this thread worked for me, so I guess I have to use my PC to rename the thousands of files my app deals with. :eek:
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Add this on the Wish
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to move or rename a file:
B4X:
Sub FileMove(SourceFolder As String, SourceFile As String, TargetFolder As String, TargetFile As String) As Boolean
   Dim source, target As JavaObject
   source.InitializeNewInstance("java.io.File", Array(SourceFolder, SourceFile))
   target.InitializeNewInstance("java.io.File", Array(TargetFolder, TargetFile))
   Return source.RunMethod("renameTo", Array(target))
End Sub

It returns True if completed successfully.
 
Upvote 0
Top