List all XML files in a directory
i would like to read all XML files of a directory. To this end I use the entryList function of QDir.
I have seen that you precise a filter to display files only, but is there a way to be more precise and display only .xml documents ?
For the moment I use the following instruction:
Re: List all XML files in a directory
Use that function:
Code:
QDir::entryList ( const QStringList & nameFilters, Filters filters
= NoFilter, SortFlags sort
= NoSort
) const
Simple example:
Code:
filters << "*.xml"; //append your xml filter. You can add other filters here
foreach
( QString file, dir.
entryList(filters,
QDir::Files) )// do wathever with *.xml files
Have look as well at http://doc.trolltech.com/4.6/qdir.html#setNameFilters
Re: List all XML files in a directory
How do I get the current file name and path within the foreach loop? I need to draw information from each one and put it into a vector.
Code:
filters << "*.txt";
foreach
(QString file, dir.
entryList(filters,
QDir::Files)){ QFile mine
(/*file path? */);
// stuff here
}
Re: List all XML files in a directory
For file name and path use QFileInfo class.
Re: List all XML files in a directory
Quote:
Originally Posted by
anbu01
For file name and path use QFileInfo class.
Exactly. Loop over entryInfoList() to get these.
Cheers,
_