Type Function Library os.* Return value Boolean and String Revision 2019.3559 Keywords rename, file See also system.pathForFile() os.remove() io.*
Renames a file or directory and returns two possible values:
trueif the file was renamed or
nilif the file was not found.
nilif rename was successful, otherwise a string describing the reason for failure.
os.rename( oldname, newname )
String. Old file name.
String. New file name.
local destDir = system.DocumentsDirectory -- Location where the file is stored local result, reason = os.rename( system.pathForFile( "orange.txt", destDir ), system.pathForFile( "apple.txt", destDir ) ) if result then print( "File renamed" ) else print( "File not renamed", reason ) --> File not renamed orange.txt: No such file or directory end