Recursively iterate over all the files in a directory and its subdirectories in Qt

前端 未结 4 1361
醉梦人生
醉梦人生 2020-12-07 15:47

I want to recursively scan a directory and all its sub-directories for files with a given extension - for example, all *.jpg files. How can you do that in Qt?

4条回答
  •  北海茫月
    2020-12-07 16:26

    Another sample which indexes all files, using QFileInfo:

    void ID3Tab::scanDir( QDir dir )
    { QFileInfoList fil = dir.entryInfoList( QStringList( "*.mp3" ),
                                             QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks,
                                             QDir::Name | QDir::IgnoreCase );
      foreach ( QFileInfo fi, fil )
        indexFile( fi );
    
      QFileInfoList dil = dir.entryInfoList( QStringList( "*" ),
                                             QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks,
                                             QDir::Name | QDir::IgnoreCase );
      foreach ( QFileInfo di, dil )
        scanDir( QDir( di.absoluteFilePath() ) );
    }
    

提交回复
热议问题