Type Function Library os.* Return value Boolean and String Revision 2017.3060 Keywords rename, file See also system.pathForFile() os.remove() io.*
Renames a file or directory and returns two possible values:
result
— true
if the file was renamed or nil
if the file was not found.reason
— nil
if rename was successful, otherwise a string describing the reason for failure.You can only rename files in the DocumentsDirectory, ApplicationSupportDirectory and TemporaryDirectory. Files in the ResourceDirectory are
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