Page 1 of 1
Batch multiple csv files to utf-8 encoding
Posted: 24 Apr 2022 00:57
by shantanu97
I have a bunch of CSV files with different encoding. How can I batch convert files in a directory for their encoding with a cmd in windows??? My final encoding is UTF-8. Ideally, what I want in the script to loop through every CSV file in the directory, and convert it to into a UTF-8.
Some files are in the directory are ANSI,UTF-16,UTF-8-BOM,UTF-16 LE BOM
ANSI --> utf-8
utf-16-->utf-8
utf-8-bom--->utf-8
utf-16-le bom --->utf-8
Re: Batch multiple csv files to utf-8 encoding
Posted: 24 Apr 2022 10:29
by aGerman
I wrote a little utility to serve those kind of tasks.
CONVERTCP
Ideally you should know the original encoding of the file and feed the utility with the right ID for every file. "Charset-guessing" is extremely error prone. So, first write the converted files into another folder (instead of overwriting the original files) in order to see how much crap you get.
Code: Select all
md "convertcp_out"
for %%i in (*.csv) do convertcp.exe ? 65001 /i "%%~i" /o "convertcp_out\%%~i"
Steffen
Re: Batch multiple csv files to utf-8 encoding
Posted: 28 Jun 2022 22:31
by shantanu97
Hi Steffen,
I am facing a problem when I am passing input folder locations in the below command.
My input folder is present on the desktop and my output folder is on documents.
How to change the below code if the input folder and output folder are in different locations. In the input folder there are a bunch of CSV files there.
Code: Select all
md "C:\Users\xyz\Documents\Test\UTF8Files"
for %%i in (C:\Users\xyz\Desktop\UTF8\Input\*.csv) do convertcp.exe ? 65001 /i "%%~i" /o "C:\Users\xyz\Documents\Test\UTF8Files\%%~i"
pause
Re: Batch multiple csv files to utf-8 encoding
Posted: 29 Jun 2022 09:13
by aGerman