0

I need to convert cp1252 files to UTF-8 with iconv and that worked fine for one file but when I try multiple files it's not working.

i try this

find . -type f -name '*.csv' -print -exec iconv -f cp1252 -t utf-8 {inputFolderPath} -o {outputFolderPath}\

it says that

File not found - '*.csv'

Malal
  • 21
  • 1
  • 1
  • Which program produces that output, find or iconv? – Ulrich Eckhardt Feb 10 '18 at 08:00
  • Uh. What OS is this? That doesn't look anything like the syntax I get for "find" on Win7. The 'cmd' tag implies this is Windows command prompt. For the linux one, tag with "bash". – Nyerguds Feb 10 '18 at 08:00
  • windows 10, I found it here https://stackoverflow.com/questions/16600835/change-encoding-multiple-file-with-iconv-in-bash – Malal Feb 10 '18 at 09:08
  • @Malal The referenced question is for a bash shell command solution for Linux and not for Windows. Do you have Iconv for Windows installed at all? This application is not pre-installed on Windows 10. What is the single command line used by you which worked? How to do you have verified that the command line used by you really worked? Has the text file which you converted from Windows-1252 to UTF-8 contained a non ASCII character with a code point value greater 127 decimal at all? – Mofi Feb 10 '18 at 14:22
  • Open a command prompt window, run `for /?` and read the output help. You would need on Windows something like `for %I in (*.csv) do iconv.exe -f cp1252 -t utf-8 "%I" -o "Path to output folder\%~nxI"` executed from within a command prompt window with current directory being the directory containing the `*.csv` files to convert from Windows-1252 to UTF-8. The output folder must exist already. Create it before if necessary with the command __MD__. See help of this command by running `md /?` in command prompt window. Run also `cd /?` which you most likely need to use also once. – Mofi Feb 10 '18 at 14:27

2 Answers2

1

If you are on Linux/UNIX, this does not apply. Since you have used the cmd tag, it is presumed this is Microsoft Windows. If not, please remove the cmd tag.

This may not be the correct command line parameters for iconv.

SET "outputFolderPath=%TEMP%

FOR /F "usebackq tokens=*" %%f IN (`DIR /A:-D "*.csv"`) DO (
    iconv -f cp1252 -t utf-8 "%%~ff" -o "%outputFolderPath%\%%~nxf"
)
lit
  • 14,456
  • 10
  • 65
  • 119
0

If all files are in one folder/directory, you can use a for-loop and write the result files into a subdirectory. Code for bash:

$ mkdir new
$ for f in *.csv; do iconv -f cp1252 -t utf-8 "$f" > new/"$f"; done

Notes:

  1. Some versions of iconv do not support the -o option, but the standard output can be redirected into a file.
  2. Enclose file names in double quotes to avoid problems with spaces.
Mike11
  • 37
  • 2