Last active
January 21, 2016 12:48
-
-
Save aminophen/cbe0bc563afc20dbaf2c to your computer and use it in GitHub Desktop.
Convert encodings of all files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
walk(){ | |
for path in $1/*; do | |
if [ -d "$path" ]; then | |
walk "$path" | |
elif [ -f "$path" ]; then | |
if [ ${path##*.} = "pdf" -o ${path##*.} = "tfm" -o ${path##*.} = "pfb" -o ${path##*.} = "vf" ]; then | |
echo "$path ignored." | |
else | |
iconv -f UTF-8 -t ISO-2022-JP "$path" >"$path.conv" | |
mv "$path.conv" "$path" | |
fi | |
fi | |
done | |
} | |
walk $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set FILEDIR=%~1 | |
cd "%FILEDIR%" | |
dir /B /S /A-D >"%FILEDIR%\filelist.txt" | |
set FILELIST=%FILEDIR%\filelist.txt | |
for /F "usebackq delims=" %%a in ("%FILELIST%") do ( | |
if "%%~xa"==".pdf" (echo "%%~a ignored.") else ( | |
if "%%~xa"==".tfm" (echo "%%~a ignored.") else ( | |
if "%%~xa"==".pfb" (echo "%%~a ignored.") else ( | |
if "%%~xa"==".vf" (echo "%%~a ignored.") else ( | |
nkf -Wj --overwrite "%%~a" | |
) | |
) | |
) | |
) | |
) | |
del %FILELIST% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
walk(){ | |
for path in $1/*; do | |
if [ -d "$path" ]; then | |
walk "$path" | |
elif [ -f "$path" ]; then | |
if [ ${path##*.} = "pdf" -o ${path##*.} = "tfm" -o ${path##*.} = "pfb" -o ${path##*.} = "vf" ]; then | |
echo "$path ignored." | |
else | |
nkf -Wj --overwrite "$path" | |
fi | |
fi | |
done | |
} | |
walk $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第一引数にディレクトリを指定すると、そのディレクトリおよびサブディレクトリのファイルを全てエンコーディング変換する。例示コードは ISO-2022-JP への変換(
nkf -Wj
およびiconv -f UTF-8 -t ISO-2022-JP
の部分;iconv には元ファイルのエンコード推定機能がないので指定必須であることに注意)。.
とするのは NG。