Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a bunch of CSV files in one folder and it seems that some of them are encoded in Unicode and some are ANSI. Is there a way to make a script so that it dynamically determines the right "codepage is xxx" in the script? I was thinking that I could just disable errors for that part of the script and load the data by using both codepages but it's something I really don't want to do. Not sure if it even works though.
Any ideas?
-Teemu
see Rob Wunderlich's post in this thread
"What I do is test the first character of the logfile with various encodings to see if I can interpret it as a number. When I get a positive I use that encoding to read the file. Probably would break if someone used a MMM-DD-YYYY format, but haven't had a complaint (yet). Here's the relevant code that determines the encoding."
FOR EACH vEncoding IN 'utf8', 'unicode', 'codepage is 1252'; TempCode: FIRST 1 // Log first row LOAD IsNum(left(@1:n,1)) as X // Test first char. Set to true if it's a number. FROM [$(_logpath)] (fix, $(vEncoding)) ; EXIT FOR WHEN peek('X'); // If a number, assume we have the right encoding. NEXT vEncoding;