类型 函数 库 os.* 返回值 字符串 和 布尔值 修订 版本 2024.3703 关键词 删除, 删除文件, 文件 另请参阅 system.pathForFile() os.rename() io.*
删除文件或目录并返回两个可能的值
result
— 如果文件成功删除,则返回 true
,否则返回 false
。reason
— 如果删除成功,则返回 nil
,否则返回描述失败原因的字符串。您只能删除 DocumentsDirectory、ApplicationSupportDirectory 和 TemporaryDirectory 中的文件。ResourceDirectory 中的文件是
os.remove( file )
字符串. 指定要删除的文件或目录名称的字符串。
local destDir = system.DocumentsDirectory -- Location where the file is stored local result, reason = os.remove( system.pathForFile( "apple.txt", destDir ) ) if result then print( "File removed" ) else print( "File does not exist", reason ) --> File does not exist apple.txt: No such file or directory end