问题描述
我有这个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> 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: 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 No need for a loop. The Edit: The OS X version of 这篇关于使用iconv将latin-1文件批量转换为utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
iconv
的OS X版本没有 -o
选项。尝试此操作:
查找。 -type f -exec bash -c'iconv -f iso-8859-1 -t utf-8{}> / path / to / destination /{}'\;
mkdir new
for a in `ls -R *`; do iconv -f iso-8859-1 -t utf-8 <"$a" >new/"$a" ; done
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/"{}" \;
-type f
option includes files and excludes directories.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/"{}"' \;