Qt实现文件夹文件 批量UTF8加BOM
批量UTF8文件除BOM
void MainWindow::on_pushButton_48_clicked()
{//选择目录除bom
QString strPath = YCTools::getFolderName();
QStringList filter = {"*.h","*.cpp","*.txt"};
QStringList stringList = YCTools::getFolderFileNames(strPath,filter);
for(auto file:stringList)
{
QByteArray byteArray;
if(YCTools::openByteFile(file,byteArray))
{
//QT TextStream读取文件自动把bom标识取消掉了!!!!!
if(isUTF8(byteArray.data())){
if( (quint8(byteArray[0]) == 0xEF) && (quint8(byteArray[1]) == 0xBB) && (quint8(byteArray[2]) == 0xBF)) {
writeEdit("文件除Bom标记\t\t" + file);
QByteArray saveArray = byteArray.right(byteArray.size() - 3);
YCTools::saveByteFile(file,saveArray);
}
}
else {
writeEdit("此文件不是UTF文件\t\t" + file);
}
}
}
}
void MainWindow::on_pushButton_47_clicked()
{//选择目录文件加bom
QString strPath = YCTools::getFolderName();
QStringList filter = {"*.h","*.cpp"};
QStringList stringList = YCTools::getFolderFileNames(strPath,filter);
for(auto file:stringList)
{
QByteArray byteArray;
if(YCTools::openByteFile(file,byteArray))
{
//QT TextStream读取文件自动把bom标识取消掉了!!!!!
if(isUTF8(byteArray.data())){
if( ((quint8)byteArray[0] == 0xEF) && ((quint8)byteArray[1] == 0xBB) && ((quint8)byteArray[2] == 0xBF)) {
//有EF BB BF说明有bom
}
else {
writeEdit("文件加Bom标记\t\t" + file);
byteArray.insert(0,"\xEF\xBB\xBF",3);
YCTools::saveByteFile(file,byteArray);
}
}
else {
writeEdit("此文件不是UTF文件\t\t" + file);
}
}
else {
return;
}
}
}