Putting / checking numbers in file names
General and Desktop
6
Posts
3
Posters
1.5k
Views
1
Watching
-
wrote on 20 May 2013, 17:29 last edited by
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)
-
wrote on 20 May 2013, 20:44 last edited by
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 -
wrote on 21 May 2013, 17:20 last edited by
thank you for your help.
f is the file or the name of the file? -
wrote on 21 May 2013, 17:49 last edited by
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.
-
wrote on 21 May 2013, 18:44 last edited by
Sorry for the omission. Exactly, f is file name.
Regards. -
wrote on 21 May 2013, 20:43 last edited by
Thank you to both of you.
1/6