Solved Remove the path of a QString file
-
Imagine we have QString file. File has directories any time. For example:
C:/Qt/5.6/mingw49_32/bin/example.xml
C:/Qt/raining/now/clouds/nature.png
D:/sun/no_clouds/newworldorder/soon.txtIs there a smart way to take the names from this file:
example.xml
nature.png
soon.txtor the last two names:
bin/example.xml
clouds/nature.png
newworldorder/soon.txtThere is the choice .remove.
But you have to know what you want to remove, for example, file.remove("C:/Qt/5.6/mingw49_32/bin/").
If you only want to remove all the folder - file names, except the last two ones?
removefolder(2, file)?
Thanks in advance.
-
@Konstantinos
Hi,
Use the specialized API in QFile, QDir and QFileInfo. For example:const QString filePath("C:/Qt/5.6/mingw49_32/bin/example.xml"); QFileInfo info(filePath); qDebug<< info.fileName() << endl << info.dir().path();
Would output:
example.xml C:/Qt/5.6/mingw49_32/bin
Kind regards.
-
Thank you for your help.