I would like to load several files into gnuplot (under Windows).
For this I use the command system(). Check the follow minimal example.
This works fine as long as there are only ANSI characters in the filenames.
Well, the greek and kyrillic alphabet might be extreme cases but characters, like ä,ö,ü,ß,é,à,ñ, ... would be nice to be handled correctly.
Of course, I could:
- rename the files to contain only ANSI-characters (not really an option)
- create a file of filenames with external tools and save it as utf-8 file and load this file list into gnuplot (to be avoided if possible)
- create such a file of filenames with gnuplot using
set print, however, gnuplot seems to save the file as ANSI encoded.
Is there a direct solution with gnuplot to handle these special characters?
Code:
### get a file list from a directory (Windows)
reset session
set encoding utf8
PATH = 'CountryTest\'
GetFileList(p,f) = sprintf('dir /b "%s%s"', p, f)
FILES = system(GetFileList(PATH,'*.dat'))
print FILES
set print "Countries.txt"
print FILES
set print
### end of code
Result1: (gnuplot 5.2.8 console, encoding utf8)
Belgi�.dat
C�te d'Ivoire.dat
Espa�a.dat
L�tzebuerg.dat
M�xico.dat
Panam�.dat
Per�.dat
Rom�nia.dat
T�rkiye.dat
�ire.dat
�sland.dat
�sterreich.dat
Cesko.dat
?????.dat
??????.dat
Result2: (file Countries.txt created by gnuplot, Notepad++ tells me that the file is ANSI encoded)
Belgi‰.dat
C“te d'Ivoire.dat
Espa¤a.dat
L‰tzebuerg.dat
M‚xico.dat
Panam .dat
Per£.dat
Romƒnia.dat
Trkiye.dat
ire.dat
Ösland.dat
™sterreich.dat
Cesko.dat
?????.dat
??????.dat
Update:
If I type the following in the Windows console:
chcp 65001 && dir /b "CountryTest\*.dat" > "CountryTest\Countries.txt"
I get the file Countries.txt:
België.dat
Côte d’Ivoire.dat
España.dat
Lëtzebuerg.dat
México.dat
Panamá.dat
Perú.dat
România.dat
Türkiye.dat
Éire.dat
Ísland.dat
Österreich.dat
Česko.dat
Ελλάς.dat
Россия.dat
However, if I use the same command in a gnuplot script:
system('chcp 65001 && dir /b "CountryTest\*.dat" > "CountryTest\Countries.txt"')
I get this file Countries.txt:
Belgi‰.dat
C“te d'Ivoire.dat
Espa¤a.dat
L‰tzebuerg.dat
M‚xico.dat
Panam .dat
Per£.dat
Romƒnia.dat
Trkiye.dat
ire.dat
Ösland.dat
™sterreich.dat
Cesko.dat
?????.dat
??????.dat
So, what is going wrong with gnuplot's system() command?
