-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathfilecountbyextwdx.lua
More file actions
40 lines (37 loc) · 1.2 KB
/
filecountbyextwdx.lua
File metadata and controls
40 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- filecountbyextwdx.lua (cross-platform)
-- 2024.07.18
--[[
Returns the number of files of the specified type (symbolic links to directories will be ignored).
No recursive search, for file search tool only!
List of extensions: see the "aExt" table.
]]
local aExt = {"png", "svg"}
function ContentGetSupportedField(FieldIndex)
if FieldIndex == 0 then
return "Number of files", table.concat(aExt, "|"), 1
end
return "", "", 0
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if FieldIndex ~= 0 then return nil end
if flags == 1 then return nil end; -- CONTENT_DELAYIFSLOW, https://doublecmd.github.io/doc/en/lua.html#preface
local k = SysUtils.FileGetAttr(FileName)
if k < 0 then return nil end
if (math.floor(k / 0x00000400) % 2 ~= 0) then return nil end
if (math.floor(k / 0x00000010) % 2 ~= 0) then
local n = 0
local r = nil
local h, d = SysUtils.FindFirst(FileName .. SysUtils.PathDelim .. "*." .. aExt[UnitIndex + 1])
if h ~= nil then
repeat
if (math.floor(d.Attr / 0x00000010) % 2 == 0) then
n = n + 1
end
r, d = SysUtils.FindNext(h)
until r == nil
SysUtils.FindClose(h)
end
return n
end
return nil
end