File encoding column
Posted: 17 Mar 2016 21:31
I need XYPlorer to show a column in detailed view showing each file encoding (UTF8, UTF16...).
Is that possible somehow?
Is that possible somehow?
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc2/
Code: Select all
return filetype(<cc_item>);
Code: Select all
Snip: CustomColumn 1
XYplorer 19.50.0244, 26.01.2019 21:59:57
Action
ConfigureColumn
Caption
Encoding
Type
3
Definition
$tool = "D:\Tools\@Command Line Tools\Git\usr\bin\file.exe";
$result = runret("""$tool"" ""<cc_item>""");
$result = regexreplace($result, "^(.+?: )(.*)", "$2");
$known = regexmatches($result, "(ASCII|UTF-8|UTF-16|UTF-32)");
if ($known) { return $known; }
return "<unknown>";
Format
0
Trigger
1
Item Type
0
Item Filter
Did you try the suggested script column (viewtopic.php?p=136174#p136174)? IMO it works pretty good if this setting is ticked:
Unfortunately, utf-8 files for the internet as per specs are supposed to be saved without BOM.highend wrote: ↑18 Mar 2016 20:04 So I guess you saved the file without BOM -> Displayed (in that column) as ASCII (because it doesn't have an identifiable header)
Character encoding is always difficult. When the file has a header, it can be (normally) determined. If it hasn't it's more or less guessing...
Alternatives:
- Save your files as UTF-8 with BOM
- Use readfile() in binary mode and check for marks yourself
- Find a better tool for guessing the encoding and use that as for the command in the custom column script
; UTF-8 characters can take 1-6 bytes, how many
; is encoded in the first character (if it has
; a character code >= 128 (highest bit set))
; For all <= 127 the ASCII is the same as UTF-8
; The number of bytes per character is stored in
; the highest bit of the first byte of the UTF-8
; character
Let me repeat my above words in a simpler fashion: It works.admin wrote: ↑26 Jan 2019 23:05Did you try the suggested script column (viewtopic.php?p=136174#p136174)? IMO it works pretty good if this setting is ticked:
Configuration | Preview | Preview | Text preview | UTF-8 auto-detection
return filetype(<cc_item>); goes wrong?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">