lua 根據路徑獲取文件名


require "lfs"

function dirpath(path)
    for file in lfs.dir(path) do   --  lfs.dir  根據路徑獲取該路徑下的文件名
        if file ~= '.' and file ~= '..' then
            local f = (path .. '/'..file)
            local attr = lfs.attributes(f) -- 該文件的各種屬性
            if attr.mode == "directory" then
                print(f .. "  -->  " .. attr.mode)
                dirpath(f)
            else
                print(f .. "  -->  " .. attr.mode)
            end

        end
    end
end
dirpath("/usr")

刪除文件: os.remove(filepath)

 

文件屬性   lfsattributes(filepath) 具體參數有下:

modification    1546497033
rdev    0
size    24
ino     4106061
mode    file
access  1559786365
blocks  8
nlink   1
uid     0
blksize 4096
gid     0
permissions     rw-r--r--
dev     51714
change  1546497033

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM