var fs = require('fs');
var path = "目标路径..";
function readDirectory(dirPath) {
if (fs.existsSync(dirPath)) {
var files = fs.readdirSync(dirPath);
files.forEach(function(file) {
var filePath = dirPath + "/" + file;
var stats = fs.statSync(filePath);
if (stats.isDirectory()) {
console.log('\n读取目录:\n', filePath, "\n");
readDirectory(filePath);
} else if (stats.isFile()) {
var buff = fs.readFileSync(filePath);
if (buff[0].toString(16).toLowerCase() == "ef" && buff[1].toString(16).toLowerCase() == "bb" && buff[2].toString(16).toLowerCase() == "bf") {
//EF BB BF 239 187 191
console.log('\发现BOM文件:', filePath, "\n");
buff = buff.slice(3);
fs.writeFile(filePath, buff.toString(), "utf8");
}
}
});
} else {
console.log('Not Found Path : ', dirPath);
}
}
readDirectory(path);
Created
November 24, 2015 12:44
-
-
Save kymtwyf/4fe6dbbc297fb1f22a0c to your computer and use it in GitHub Desktop.
Intellij Error(1,1)illegalcharacter '\ufeff'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment