Results 1 to 5 of 5

Thread: Searching files from directories & its subdirectories

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Searching files from directories & its subdirectories

    Hi All,

    I am trying to search files from directories & its subdirectories. I want to do recursive searching. I am unable to find option to do it.
    Please tell me the way to do recursive searching using QFileDialog.

    Thanks in advance!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Searching files from directories & its subdirectories

    You have to get the entries of a directory and then iterate over every single file and check whether it is a directory itself. If that is true, you recursively start the function on that file. Take a look at the entryList() and entryInfoList() members of QDir.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Searching files from directories & its subdirectories

    See this post for how to recursively iterate through a directory and its subdirectories: http://www.qtcentre.org/forum/p-recu...ostcount2.html. Alternatively, you could abuse QDirModel and QAbstractItemModel::match().
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Searching files from directories & its subdirectories

    ugly implementation to give you a little bit of a hint on how to do it.

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. void listFiles(QDir, QString);
    5.  
    6. //#include "main.moc"
    7. int main(int argc, char* argv[])
    8. {
    9. QApplication(argc, argv);
    10. QDir dir("mydir");
    11. listFiles(dir, "");
    12. return 0;
    13. }
    14.  
    15.  
    16. void listFiles(QDir directory, QString indent)
    17. {
    18. indent += "\t";
    19. QDir dir(directory);
    20. QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
    21. foreach(QFileInfo finfo, list) {
    22. qDebug() << indent + finfo.fileName() << endl;
    23. if (finfo.isDir()) {
    24. listFiles(QDir(finfo.absoluteFilePath()), indent);
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Searching files from directories & its subdirectories

    //Show All Files On Folder And Sub-folder With extinction "*.mov"

    ui->listWidget_2->clear();

    QStringList nameFilters;

    nameFilters << "*.mov";



    QDirIterator dirIterator(ui->TextPath->toPlainText(),nameFilters, QDir::Files, QDirIterator::Subdirectories);
    while (dirIterator.hasNext()) {
    ui->listWidget_2->addItem(dirIterator.next());
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.