D
D
Dmitry Tarasov2017-07-08 17:24:12
linux
Dmitry Tarasov, 2017-07-08 17:24:12

How to convert project files from CP866 to UTF-8?

In general, you need to convert project files from cp866 encoding to utf-8.
I try like this

find project/method_pay -name "*.*" -exec iconv -f CP866 -t UTF-8 {} -o target/{} \;

There is such an error
iconv: -o: No such file or directory
iconv: target/project/method_pay/method_pay_json.php: No such file or directory

I try again with gulp
const gulp = require('gulp');
const convertEncoding = require('gulp-convert-encoding');

gulp.task('default', function () {
  return gulp.src('project/method_pay/*.*')
    // .pipe(convertEncoding({to: 'utf8'}))
    .pipe(convertEncoding({decode: 'CP866', encode: 'utf8'}))
    .pipe(gulp.dest('dist'));
});

There are such errors
[email protected] start /Users/fast/Sites/untitled
> gulp

[16:54:45] Using gulpfile ~/Sites/untitled/gulpfile.js
[16:54:45] Starting 'default'...
[16:54:45] 'default' errored after 8.48 ms
[16:54:45] Error in plugin 'gulp-convert-encoding'
Message:
    At least one of `from` or `to` required
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `gulp`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/fast/.npm/_logs/2017-07-08T13_54_45_124Z-debug.log
BRAIN:untitled fast$

Maybe there is some other way, well, or help with these non-working ones.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AVKor, 2017-07-08
@fast-je

enconv file.txt
dos2unix file.txt

The first one changes the encoding (input and output are determined automatically; in Linux, the default output is UTF-8).
The second changes the EOL.

S
Sergey Lerg, 2017-07-08
@Lerg

Try Python

import codecs
import os

for root, dirs, files in os.walk('.'):
  for file in files:
    f = codecs.open(file, "r", "cp866")
    contents = f.read()
    f.close()
    f = codecs.open(file, "w", "utf-8")
    f.write(contents)
    f.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question