Napisałem do tego program. Przedtem działał dobrze, a teraz jak robię to hurtowo dla wszystkich plików to po zapisie usuwa mi polskie znaki. Oto program:
Kod: Zaznacz cały
#include <QtCore>
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <iostream>
using namespace std;
int main()
{
QString folder = "/home/peer/studia/!Praca inżynierska!/Praca inżynierska/LaTex/Rozdzialy/";
QTextCodec::setCodecForTr (QTextCodec::codecForName ("UTF-8"));
int filesValue = 5;
for(int fi=1; fi<=6; fi++)
{
for(int j=1; j<=filesValue; j++)
{
QString fileNameWithFolder = folder + QString("%1/%1.%2.tex").arg(fi).arg(j);
QString fileName = fileNameWithFolder;
fileName.remove( folder + QString("%1/").arg(fi) );
QFile f( fileNameWithFolder );
if( !f.exists() )
{
// It does not exist
qDebug()<< fileNameWithFolder;
qDebug() << "The file "<< fileName <<" does not exist.";
break;
}
// It exists, open it
if( !f.open( QFile::ReadOnly ) )
{
// It could not open
std::cout << "Failed to open." << std::endl;
return 0;
}
QTextStream file(&f);
QString text = file.readAll();
for(char i='a'; i <= 'z'; i++)
{
text = text.replace(QString(" ")+QString(i)+QString(" "), QString(" ")+QString(i)+QString("~"));
}
for(char i='A'; i <= 'Z'; i++)
{
text = text.replace(QString(" ")+QString(i)+QString(" "), QString(" ")+QString(i)+QString("~"));
}
// qDebug() << text;
QFile file2("tex/" + fileName);
if( !file2.open(QIODevice::WriteOnly | QIODevice::Text) )
{
qDebug()<< "Error file" << fileName <<"can't save";
}
QTextStream out(&file2);
out << text;
file2.close();
f.close();
}
}
}
Dla zrozumienia programu powiem że mam takie drzewo folderów:
Kod: Zaznacz cały
Rozdzialy/
├── 1
│ ├── 1.1.tex
│ ├── 1.1.tex~
│ ├── 1.1.tex.backup
│ ├── 1.2.tex
│ ├── 1.2.tex~
│ ├── 1.2.tex.backup
│ ├── 1.aux
│ ├── 1.tex
│ ├── 1.tex~
│ ├── 1.tex.backup
│ ├── RoboMouse.eps
│ ├── RoboMouse_interfejs.png
│ └── RoboMouse.png
├── 2
│ ├── 2.1.tex
│ ├── 2.1.tex~
│ ├── 2.2.tex
│ ├── 2.2.tex~
│ ├── 2.2.tex.backup
│ ├── 2.3.tex
│ ├── 2.3.tex~
│ ├── 2.3.tex.backup
│ ├── 2.4.tex
│ ├── 2.4.tex~
│ ├── 2.aux
│ ├── 2.tex
│ ├── 2.tex~
│ ├── 2.tex.backup
│ └── backup
│ ├── old_2.1.tex
│ ├── old_2.2.tex
│ ├── old_2.3.tex
│ └── old_2.4.tex
├── 3
│ ├── 3.1.tex
│ ├── 3.1.tex~
│ ├── 3.1.tex.backup
│ ├── 3.2.tex
│ ├── 3.2.tex~
│ ├── 3.2.tex.backup
│ ├── 3.3.tex
│ ├── 3.3.tex~
│ ├── 3.3.tex.backup
│ ├── 3.4.tex
│ ├── 3.4.tex~
│ ├── 3.4.tex.backup
│ ├── 3.5.tex
│ ├── 3.5.tex~
│ ├── 3.5.tex.backup
│ ├── 3.aux
│ ├── 3.tex
│ ├── 3.tex~
│ ├── 3.tex.backup
│ ├── ATmega8.png
│ ├── backup
│ │ ├── 3.2.tex
│ │ └── 3.3.tex
│ ├── DB9_RS232_pinout.gif
│ ├── DB9_RS232_pinout.png
│ ├── ols_3.1.tex
│ ├── ramka.bmp
│ ├── ramka.png
│ └── wtyczka_db9.png
├── 4
│ ├── 4.1.tex
│ ├── 4.1.tex~
│ ├── 4.1.tex.backup
│ ├── 4.2.tex
│ ├── 4.2.tex~
│ ├── 4.2.tex.backup
│ ├── 4.3.tex
│ ├── 4.3.tex~
│ ├── 4.3.tex.backup
│ ├── 4.4.tex
│ ├── 4.4.tex~
│ ├── 4.4.tex.backup
│ ├── 4.aux
│ ├── 4.tex
│ ├── 4.tex~
│ ├── Schemat_big.png
│ └── Schemat.png
├── 5
│ ├── 5.1.tex
│ ├── 5.1.tex~
│ ├── 5.1.tex.backup
│ ├── 5.2.tex
│ ├── 5.2.tex~
│ ├── 5.2.tex.backup
│ ├── 5.3.tex
│ ├── 5.3.tex~
│ ├── 5.4.tex
│ ├── 5.4.tex~
│ ├── 5.aux
│ ├── 5.tex
│ └── 5.tex~
└── 6
├── 6.aux
├── 6.tex
└── 6.tex~
8 directories, 92 files
Kod: Zaznacz cały
QTextStream file(&f);
file.setCodec("UTF-8");
QString text = file.readAll().toUtf8();