-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfilenamewdx.lua
62 lines (57 loc) · 1.43 KB
/
filenamewdx.lua
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
-- filenamewdx.lua (cross-platform)
-- 2021.10.07
--[[
Returns parts of full filename.
Supported fields: see table "fields".
]]
local fields = {
"Full name",
"Name",
"Base name",
"Extension",
"Path",
"Parent folder"
}
function ContentGetSupportedField(FieldIndex)
if fields[FieldIndex + 1] ~= nil then
return fields[FieldIndex + 1], "", 8
end
return "", "", 0
end
function ContentGetDefaultSortOrder(FieldIndex)
return 1; --or -1
end
function ContentGetDetectString()
return 'EXT="*"'
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if FieldIndex == 0 then
return FileName
elseif FieldIndex == 1 then
return SysUtils.ExtractFileName(FileName)
elseif FieldIndex == 2 then
local t = SysUtils.ExtractFileName(FileName)
local e = SysUtils.ExtractFileExt(t)
if string.len(e) > 1 then
return string.sub(t, 1, string.len(t) - string.len(e))
else
return t
end
elseif FieldIndex == 3 then
local t = SysUtils.ExtractFileExt(FileName)
if string.len(t) > 1 then
return string.sub(t, 2, -1)
else
return nil
end
elseif FieldIndex == 4 then
return SysUtils.ExtractFileDir(FileName)
elseif FieldIndex == 5 then
local t1 = SysUtils.ExtractFileDir(FileName)
local t2 = SysUtils.ExtractFileDir(t1)
local t = string.sub(FileName, string.len(t2) + 2, string.len(t1))
if t == "" then return nil else return t end
else
return nil
end
end