os.remove()

类型 函数
os.*
返回值 字符串布尔值
修订 版本 2024.3703
关键词 删除, 删除文件, 文件
另请参阅 system.pathForFile()
os.rename()
io.*

概述

删除文件或目录并返回两个可能的值

注意事项

您只能删除 DocumentsDirectoryApplicationSupportDirectoryTemporaryDirectory 中的文件。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