0

I am trying to convert a set of Windows 10 files in a directory from ANSI to UTF-8. I have found the following command that works in a command prompt for a single file if the command is run from the folder where the source file exists:

piconv -f windows-1252 -t UTF-8 < SOURCE_File.txt > TARGET_File.txt

However, I need some way of doing this for ALL files in a chosen folder. I thought I could use perl with the command:

my $Test=system("piconv","-f", "windows-1252", "-t", "UTF-8"," < $SOURCE_File > ","$TARGET_File");

where $SOURCE_File and $TARGET_File will, in general, contain the full paths of the files.

BUT, this does no work! I get errors such as Invalid argument or can't open file.

Does anyone know how to put the piconv command in a perl script. I can set up the looping for each file in a given directory I just cannot work out the piconv command that converts each file.

Many thanks

Gauss76

1 Answer 1

0

Put all arguments of piconv in a single string:

system("piconv -f windows-1252 -t UTF-8 $SOURCE_File >$TARGET_File");
2
  • OK, it seems as though I have missed the obvious, AGAIN! Many thanks Toto for your help.
    – gauss76
    Sep 19, 2017 at 12:11
  • @gauss76: You're welcome, glad it helps.
    – Toto
    Sep 19, 2017 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.