-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtarfilescountwdx.lua
More file actions
62 lines (56 loc) · 1.76 KB
/
Copy pathtarfilescountwdx.lua
File metadata and controls
62 lines (56 loc) · 1.76 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local cmd = "tar -tvf"
local filename = ''
local files = 0;
local folders = 0;
local symlinks = 0;
local fields = {
{"files", 2},
{"folders", 2},
{"symlinks", 2},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil ) then
return fields[FieldIndex + 1][1], "", fields[FieldIndex + 1][2];
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetDetectString()
return '(EXT="TAR")|(EXT="GZ")|(EXT="BZ2")|(EXT="LZMA")|(EXT="XZ")|(EXT="TGZ")|(EXT="TBZ")|(EXT="TBZ2")|(EXT="TZMA")|(EXT="TZX")|(EXT="TLZ")';
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if (filename ~= FileName) then
local attr = SysUtils.FileGetAttr(FileName);
if (attr < 0) or (math.floor(attr / 0x00000004) % 2 ~= 0) or (math.floor(attr / 0x00000010) % 2 ~= 0) then
return nil;
end
files = 0;
folders = 0;
symlinks = 0;
local handle = io.popen(cmd .. ' "' .. FileName:gsub('"', '\\"') .. '"', 'r');
local output = handle:read("*a");
handle:close();
if (output == '') or (output == nil) then
return nil;
end
filename = FileName;
for line in output:gmatch("([^\n]*)\n?") do
if (line:find("^d[^\n]+")) then
folders = folders + 1;
end
if (line:find("^%-[^\n]+")) then
files = files + 1;
end
if (line:find("^l[^\n]+")) then
symlinks = symlinks + 1;
end
end
end
if (FieldIndex == 0) then
return files;
elseif (FieldIndex == 1) then
return folders;
elseif (FieldIndex == 2) then
return symlinks;
end
return nil; -- invalid
end