#1 2016-04-12 21:17

Ferroginus
Member
Registered: 2016-04-12
Posts: 1

Small script to convert filenames UTF8 to ANSI.

Hi,

I have not found a script (or a simpler way to do it), so I have made this small one.

begin
  Filename := UTF8decode(Filename);
  FileName := WideToAnsi(FileName);
end.

Example:
From these

Las Matemáticas No Dan Más Que Problemas (Juan Luis Roldán Calzado).pdf
Matemática... Estás Ahí - Episodio 2 (Adrián Paenza).pdf
Qué Es Un Acertijo (Elías Loyola Campos).pdf

To these

Las Matemáticas No Dan Más Que Problemas (Juan Luis Roldán Calzado).pdf
Matemática... Estás Ahí - Episodio 2 (Adrián Paenza).pdf
Qué Es Un Acertijo (Elías Loyola Campos).pdf

Offline

#2 2016-04-12 22:26

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: Small script to convert filenames UTF8 to ANSI.

Thanks for sharing!

Just a note for readers:
You may not be able to reproduce the demonstrated example because it is based on a specific system locale.

Offline

#3 2016-11-10 12:52

ene
Member
Registered: 2016-11-10
Posts: 4

Re: Small script to convert filenames UTF8 to ANSI.

Hi,

Oem to Ansi, is it possible? By Pascalscript or other?

I would like:

LŽS_MIG
B”RSE

to become this:

LÄS_MIG
BöRSE

Offline

#4 2016-11-10 21:28

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: Small script to convert filenames UTF8 to ANSI.

ene wrote:

Oem to Ansi, is it possible? By Pascalscript or other?

There is no such function in Pascal Script at the moment, but it can be added if it will help.

Where is your OEM text coming from?

Offline

#5 2016-11-11 04:47

ene
Member
Registered: 2016-11-10
Posts: 4

Re: Small script to convert filenames UTF8 to ANSI.

Doesn't happen very often, it's true. It's beacause I put on my disk old files from Atari ST which used oem code back in the days. Some Swedish files (like above) or German files have accents that are not properly converted once extracted.

Not really important btw, was just wondering if a little script would do the trick (like in the first post) in the Pascalscript field; I googled a bit and tried ConvertOemToAnsi, but then I have no idea how it works.

Offline

#6 2016-11-11 10:43

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: Small script to convert filenames UTF8 to ANSI.

It's hard to say what the effects would be of moving files from an OEM encoded system into Windows. Your file names may get corrupted or perhaps mangled (as you see them). Simply applying OEM to ANSI conversion may not fix them, however, it is worth a try.

Have you tested OEM to ANSI conversion on any of your filenames?

For example, UltraEdit seems to have this feature, try it on a few filenames. This is just the first search result, there may be other tools available.

If it works, then you can load all your files into ReNamer, click Preview without any rules, Export new names into clipboard (using the Export menu above the files table). Then, use your OEM to ANSI conversion tool. Then, add converted filenames into a User Input rule in ReNamer.

If OEM to ANSI conversion does not fix your filenames, then your last resort may be to manually map source-to-target characters (e.g. "Ž" > "Ä") in the Translit rule in ReNamer.

Offline

#7 2016-11-11 20:58

ene
Member
Registered: 2016-11-10
Posts: 4

Re: Small script to convert filenames UTF8 to ANSI.

den4b wrote:

It's hard to say what the effects would be of moving files from an OEM encoded system into Windows. Your file names may get corrupted or perhaps mangled (as you see them). Simply applying OEM to ANSI conversion may not fix them, however, it is worth a try.

Have you tested OEM to ANSI conversion on any of your filenames?

It's just about accents, the files themselves are fine believe me smile, I've been doing this from a long time. There are strange characters when they have accents and once put into Windows but that's about it (content is not affected).


den4b wrote:

For example, UltraEdit seems to have this feature, try it on a few filenames. This is just the first search result, there may be other tools available.

If it works, then you can load all your files into ReNamer, click Preview without any rules, Export new names into clipboard (using the Export menu above the files table). Then, use your OEM to ANSI conversion tool. Then, add converted filenames into a User Input rule in ReNamer.

I think I understand what you mean (but then my english is poor) . Actually, I have a software that is able to convert text from OEM TO ANSI.  I haven't thought about the Export thing in Renamer, but anyway I tried to 'Import new names from clipboard' (with a template converted to ansi) and it works fine.

But the problem is that I have a folder with lots of files, so it would suppose I already have the templates for the files that need them  (I know about LŽS_MIG, B”RSE, ok, but I don't know the rest). I would have expected from Renamer to have something like a 'OEM -> ANSI' rule, so I could just drag my  files into it so that it could 'auto-detect' those with accents and ignore the rest (I hope you follow me..).


So basically it requires from me to do some tedious tasks, thing that Renamer is supposed to avoid wink (I'm joking of course, your software is really great), I asked because it has a lot a features so I thought it could be possible.

Thank you for your help and suggestions, that's nice of you.

Last edited by ene (2016-11-11 20:59)

Offline

#8 2016-11-12 09:10

ene
Member
Registered: 2016-11-10
Posts: 4

Re: Small script to convert filenames UTF8 to ANSI.

I've proceeded this way: listed the content of the folder with a catalag tool, searched for any strange characters in the list

A_B”RSE, ZNDER ZB„CKER, LŽS_MIG, L„S_MIG...

used OEM -> ANSI with a text converter software, imported new names from clipboard in Renamer as you mentionned, applied the rule..

LÄS_MIG
LäS_MIG
A_BöRSE.GFA
SMÅTT_O_.GOT
ZüNDER
ZBäCKER
FORMULÄR
ZüND
INNEHÅLL

So it works as expected but requires little work (nothing terrible though). Thank you for your advice, I wouldn't have found it myself.

Offline

#9 2016-11-12 17:50

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: Small script to convert filenames UTF8 to ANSI.

I'm glad that you have worked it out.

ene wrote:

I've proceeded this way: listed the content of the folder with a catalag tool...

You can add all your files into ReNamer and export original names using the built-in "Export new names into clipboard" option, instead of using a separate catalog tool. Then, apply OEM to ANSI conversion and import back into ReNamer using "Import new names into clipboard" option or a User Input rule.

By the way, several new functions were added to PascalScript in v6.6.0.2 Beta: OemToAnsi, OemToWide, AnsiToOem, WideToOem. These might actually help you achieve what you need all inside of ReNamer.

However, you may need to experiment a bit with variations of Ansi/Wide/Oem conversion functions to get it working. That is because the files are actually presented as WideString (UTF16) type by the operating system and it is not clear what conversion operations have been applied to the original OEM to get a mangled UTF16.

Good luck!

Offline

Board footer

Powered by FluxBB