Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Helix751
Senior Member
Senior Member
Posts: 231
Joined: 2004-06-16, 21:16 UTC
Location: Chile

Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Helix751 »

The Subject should be self-explanatory. Is there a command or if not, a plugin that allows to manipulate and convert (especially in batch a group of files) from one encoding to another one?

Thanks
Regards,
Sergio

TCmd license #12059
TC11.03x86/x64 | Win11 Pro
User avatar
nsp
Power Member
Power Member
Posts: 1827
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *nsp »

To my knowledge, i do not know any packer who can convert txt file from one encoding to another.
As alternat suggestion, you can use TCBL or any script able to handle a list of file (%L or %S) an use iconv or similar.
iconv from gnuwin32.
wconv from texttools....
User avatar
Helix751
Senior Member
Senior Member
Posts: 231
Joined: 2004-06-16, 21:16 UTC
Location: Chile

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Helix751 »

I'm currently using Notepad++, but the conversion is on a file-by-file basis.

The ability to convert a group of files in a folder directly from within TC would be a time saver.

Yesterday I found a (pretty old) packer plugin that (among regexp substitutions and other functions) can also be used for ANSI->UTF-8, though it doesn't do the needed UTF-8->ANSI conversion.

RegXtract: https://totalcmd.net/plugring/reg_ext.html
Regards,
Sergio

TCmd license #12059
TC11.03x86/x64 | Win11 Pro
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6537
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Horst.Epp »

My editor PSPad has the needed conversion under
Encoding > Batch encoding conversion

http://www.pspad.com/en/
Windows 11 Home x64 Version 23H2 (OS Build 22631.3737)
TC 11.03 x64 / x86
Everything 1.5.0.1383a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.78
QAP 11.6.3.3 x64
User avatar
Helix751
Senior Member
Senior Member
Posts: 231
Joined: 2004-06-16, 21:16 UTC
Location: Chile

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Helix751 »

Thanks @Horst.Epp. Not the perfect solution (given TC is the main goal of this thread), but it would surely help.

I hope a plugin for this may be developed in the future (as sw developing sadly exceeds my skills :roll: ).

[edit] Found a temporary solution with Notepad++
- Open the file
- Start macro recording
- Do the conversion
- Save and close the file

Then, I can run the 'Run Macro multiple times' from the Macro menu with several opened files.

Again, not perfect, but does the job.
Regards,
Sergio

TCmd license #12059
TC11.03x86/x64 | Win11 Pro
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6537
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Horst.Epp »

Helix751 wrote: 2023-08-06, 15:54 UTC Thanks @Horst.Epp. Not the perfect solution (given TC is the main goal of this thread), but it would surely help.

I hope a plugin for this may be developed in the future (as sw developing sadly exceeds my skills :roll: ).

[edit] Found a temporary solution with Notepad++
- Open the file
- Start macro recording
- Do the conversion
- Save and close the file

Then, I can run the 'Run Macro multiple times' from the Macro menu with several opened files.

Again, not perfect, but does the job.
The PSPad version does this much easier
- Select your files/dirs, incl. Sub-dirs if needed
- Set the from/to encoding option
- Start
Windows 11 Home x64 Version 23H2 (OS Build 22631.3737)
TC 11.03 x64 / x86
Everything 1.5.0.1383a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.78
QAP 11.6.3.3 x64
User avatar
Helix751
Senior Member
Senior Member
Posts: 231
Joined: 2004-06-16, 21:16 UTC
Location: Chile

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Helix751 »

2Horst.Epp The only issues here are this isn't a TC solution and I don't use PSPad nor have it installed (despite its small size). I gave it a try it in the past, but at last sticked with N++ and don't have the time to switch editors again. Thanks for the suggestion, anyway.
Regards,
Sergio

TCmd license #12059
TC11.03x86/x64 | Win11 Pro
hi5
Power Member
Power Member
Posts: 555
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *hi5 »

Just in case you want to use TC to identify files before opening them, you can try EnfInfo https://www.ghisler.ch/board/viewtopic.php?t=38408

Edit: if powershell is an option you can find powershell scripts to (batch) convert files as well (just google it), there are probably command line tools as well so you can call these in a batch file via a button or short cut
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
User avatar
Usher
Power Member
Power Member
Posts: 1677
Joined: 2011-03-11, 10:11 UTC

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Usher »

Helix751 wrote: 2023-08-06, 17:44 UTCthis isn't a TC solution
As you should understand from previous comments, codepage conversion is a feature of good text editors. TC does not provide ANY text editor, so you shouldn't expect any TC solution for codepage conversion.
Andrzej P. Wozniak
Polish subforum moderator
User avatar
Stefan2
Power Member
Power Member
Posts: 4204
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: command to convert ANSI<->UTF-8 or other encodings?

Post by *Stefan2 »

Helix751 wrote: 2023-08-06, 02:16 UTC The Subject should be self-explanatory. Is there a command or if not, a plugin that allows to manipulate and convert (especially in batch a group of files) from one encoding to another one?

Thanks

You may try this copy&paste button-code with an PowerShell script:

- select the file(s) and execute this button

--------------------------------
TOTALCMD#BAR#DATA
powershell -noexit
Get-Content '%F'|ForEach{$N=$((GI $_).BaseName +'_UTF8'+(GI $_).Extension);$_;$N;Get-Content $_|Set-Content $N -Encoding UTF8}
powershell
Encode selected file(s) to unicode;bigendianunicode;utf8;utf7;utf32;ascii(ANSI);default;oem


-1
--------------------------------

There will be new, converted files created, with the encoding mode written to the filename.

Change the string UTF8 to the wanted one, f.ex. ascii:
Get-Content '%L'|ForEach{$N=$((GI $_).BaseName +'_UTF8'+(GI $_).Extension);$_;$N;Get-Content $_|Set-Content $N -Encoding UTF8}
Get-Content '%L'|ForEach{$N=$((GI $_).BaseName +'_ascii'+(GI $_).Extension);$_;$N;Get-Content $_|Set-Content $N -Encoding ascii}
Capabilities are one off unicode;bigendianunicode;utf8;utf7;utf32;ascii(ANSI);default;oem

VON:
HISTORY.txt
LIESMICH.TXT
README.TXT
ZU:
HISTORY_UTF8.txt
LIESMICH_UTF8.TXT
README_UTF8.TXT







Perhaps a better approach is to save the converted files while keeping there name into a new sub folder named 'encoded':
--------------------------------
TOTALCMD#BAR#DATA
powershell -noexit
$N='encoded';If(-Not(Test-Path $N)){New-Item $N -type 'dir'}; Get-Content '%F'|ForEach{Get-Content $_ | Set-Content $N\$_ -Encoding UTF8}
powershell
Encode selected file(s) to unicode;bigendianunicode;utf8;utf7;utf32;ascii;default;oem


-1
--------------------------------


VON:
HISTORY.txt
LIESMICH.TXT
README.TXT
ZU:
encoded\HISTORY.txt
encoded\LIESMICH.TXT
encoded\README.TXT





You can also change the script code to just overwrite the existing files with the encoded version.




HTH? :D
 
Fla$her
Power Member
Power Member
Posts: 2398
Joined: 2020-01-18, 04:03 UTC

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Fla$her »

2Helix751

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_PATH%\Utils\nhrt\nhrt.exe
-cp:auto,utf8bom -notitle -o:q %S
wcmicon2.dll,67
Change the encoding of the selected text files to UTF-8

1
nhrt
Overquoting is evil! 👎
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6537
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Horst.Epp »

2Fla$her
Thanks for the nhrt link.
Nice useful tool :)
Windows 11 Home x64 Version 23H2 (OS Build 22631.3737)
TC 11.03 x64 / x86
Everything 1.5.0.1383a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.78
QAP 11.6.3.3 x64
Fla$her
Power Member
Power Member
Posts: 2398
Joined: 2020-01-18, 04:03 UTC

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Fla$her »

2Horst.Epp
You're welcome. I've been using it for many years. ✌
Overquoting is evil! 👎
User avatar
Helix751
Senior Member
Senior Member
Posts: 231
Joined: 2004-06-16, 21:16 UTC
Location: Chile

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Helix751 »

2Fla$her
Thanks for the tip! Looks and works quite fine.
Regards,
Sergio

TCmd license #12059
TC11.03x86/x64 | Win11 Pro
Fla$her
Power Member
Power Member
Posts: 2398
Joined: 2020-01-18, 04:03 UTC

Re: Internal command/plugin to convert ANSI<->UTF-8 or other encodings?

Post by *Fla$her »

2Helix751
I accidentally stumbled upon the plugin when I was looking through the build folders. 👨‍💻
Overquoting is evil! 👎
Post Reply