判断一个文件或目录是否存在 (pfile.exists)

声明

是否存在, 文件类型 = pfile.exists(文件路径)

参数及返回值

  • 是否存在
    • 布尔型,True: 文件或目录存在,False:文件或目录不存在
  • 文件类型
    • 当不存在,本参数返回为nil
      • "file", 路径是一个文件
      • "directory", 路径是一个目录

说明

用于判断一个路径是文件还是目录还是不存在

pfile模块操作手机设备文件,如果你要操作ATP服务器的文件,请使用file模块。

示例

local r, t = pfile.exists("/var/mobile/1.zip")
if r then
    print("`/var/mobile/1.zip` 存在")
else
    print("`/var/mobile/1.zip` 不存在")
end
--
local r , t = pfile.exists("/var/mobile/1.zip")
if t =="file" then
    print("`/var/mobile/1.zip` 存在并且是个文件")
else
    print("`/var/mobile/1.zip` 不是文件")
end
--
local r,t = pfile.exists("/var/mobile/123/")
if t =="directory" then
    print("`/var/mobile/123/` 存在并且是个目录")
else
    print("`/var/mobile/123/` 不是目录")
end
powered by GitbookFile Modify: 2021-03-27 23:14:19

results matching ""

    No results matching ""