本文介绍了使用iconv将latin-1文件批量转换为utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个PHP项目在我的OSX是在latin1 -encoding。现在我需要将文件转换为UTF8。我不是一个shell编码器,我尝试从互联网找到的东西:

  mkdir new 
for a `ls -R *`; do iconv -f iso-8859-1 -t utf-8<$ a> new /$ a; done

但是这不会创建目录结构,它给我运行时的错误加载。

解决方案

您不应该使用 ls 这样, for 循环也不合适。此外,目标目录应该在源目录之外。

  mkdir / path / to / destination 
find。 -type f -exec iconv -f iso-8859-1 -t utf-8{}-o / path / to / destination /{}\;

无需循环。 -type f 选项包括文件和排除目录。



p>

iconv 的OS X版本没有 -o 选项。尝试此操作:

 查找。 -type f -exec bash -c'iconv -f iso-8859-1 -t utf-8{}> / path / to / destination /{}'\; 


I'm having this one PHP project on my OSX which is in latin1 -encoding. Now I need to convert files to UTF8. I'm not much a shell coder and I tried something I found from internet:

mkdir new  
for a in `ls -R *`; do iconv -f iso-8859-1 -t utf-8 <"$a" >new/"$a" ; done

But that does not create the directory structure and it gives me heck load of errors when run. Can anyone come up with neat solution?

解决方案

You shouldn't use ls like that and a for loop is not appropriate either. Also, the destination directory should be outside the source directory.

mkdir /path/to/destination
find . -type f -exec iconv -f iso-8859-1 -t utf-8 "{}" -o /path/to/destination/"{}" \;

No need for a loop. The -type f option includes files and excludes directories.

Edit:

The OS X version of iconv doesn't have the -o option. Try this:

find . -type f -exec bash -c 'iconv -f iso-8859-1 -t utf-8 "{}" > /path/to/destination/"{}"' \;

这篇关于使用iconv将latin-1文件批量转换为utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 06:24