Putting / checking numbers in file names
-
Hi,
I am using QT4 with QtCreator and windowsXP.I would like to save text-files in giving them names made with letters and a number at the end (for example cours12).
- Checking the last number used for the files (cours1/cours2/cours3/cours4 already exist)
2)5 is not used yet. Thus cours5 has to be created and saved
Could you help me to do this. Thank you in advance
- Checking the last number used for the files (cours1/cours2/cours3/cours4 already exist)
-
Hi phil63, you can use something like this
@int n = 0;
while (true){
QString f = qApp->tr("cours%1.txt").arg(n);
if (! QFile::exists ( f ))
break;
else
n += 1;
}
//here you can continue and create coursN file
@Hope it's util.
Regards -
the static method "exists":http://qt-project.org/doc/qt-4.8/qfile.html#exists takes a string. So, it must be the name of the file.
-
Sorry for the omission. Exactly, f is file name.
Regards.