Collections: add books from a folder (#12892)

This commit is contained in:
hius07
2024-12-15 18:22:05 +02:00
committed by GitHub
parent 72086b7a26
commit f025cce059
3 changed files with 60 additions and 13 deletions

View File

@@ -783,7 +783,8 @@ end
--- Recursively scan directory for files inside
-- @string path
-- @func callback(fullpath, name, attr)
function util.findFiles(dir, cb)
function util.findFiles(dir, cb, recursive)
recursive = recursive ~= false
local function scan(current)
local ok, iter, dir_obj = pcall(lfs.dir, current)
if not ok then return end
@@ -792,7 +793,7 @@ function util.findFiles(dir, cb)
-- lfs can return nil here, as it will follow symlinks!
local attr = lfs.attributes(path) or {}
if attr.mode == "directory" then
if f ~= "." and f ~= ".." then
if recursive and f ~= "." and f ~= ".." then
scan(path)
end
elseif attr.mode == "file" or attr.mode == "link" then