Regular Expression Sort #1436
Replies: 2 comments
-
For what? There are plugins and we can change the file name or use part of it in a separate column and use this column for independent sorting.. -- (cross-platform)
-- 2024..
--[[
Script uses the "string.gsub" function, see description and examples here
https://www.lua.org/manual/5.1/manual.html#pdf-string.gsub
About patterns: https://www.lua.org/manual/5.1/manual.html#5.4.1
How to use the "fields" table:
{"Skip prefix", "^[^%a]+", "", 0},
where
- "Skip prefix" is the name of field;
- "^[^%a]+" - what to look for;
- "" is used for replacement (i.e. empty string in this case);
- 1 - the number of replacements: 1, 2, 3 and so on. 0 means all occurrences.
]]
local fields = {
{"Skip prefix", "^[^%a]+", "", 1},
{"Replace prefix", "^DSC_", "IMG_", 1}
}
function ContentGetSupportedField(FieldIndex)
if fields[FieldIndex + 1] ~= nil then
return fields[FieldIndex + 1][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 >= #fields then return nil end
local sResult
local sFile = SysUtils.ExtractFileName(FileName)
if fields[FieldIndex + 1][4] == 0 then
sResult = string.gsub(sFile, fields[FieldIndex + 1][2], fields[FieldIndex + 1][3])
else
sResult = string.gsub(sFile, fields[FieldIndex + 1][2], fields[FieldIndex + 1][3], fields[FieldIndex + 1][4])
end
return sResult
end Details at the beginning of the script. "Skip prefix" will show the name without prefixes similar to P.S. But I'm not sure I understood the essence of this suggestion correctly. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply, it has assisted me in getting a new column that displays part of a filename - you understood the question correctly. |
Beta Was this translation helpful? Give feedback.
-
Can we have a "sort by regular expression" feature?
I quite often want to sort by a section of the file name.
Beta Was this translation helpful? Give feedback.
All reactions