Qt List File And Directory
Qt List File And Directory
In this tutorial, I will create a tutorial how Qt List File And Directory at a location. From this method, we can know list all files and directory, only directory or only files at location we defined. In this Qt List File And Directory tutorial, I create a simple form with radio button to select method we want. You can choose to search files and directory, only directory or only files at a location. I use some function in QFile, QDir and QFileInfo to searching this file or directory. This is a algoritm how we can get Filename and Directory at a location with this Qt List File And Directory tutorial :
//list file and directory function bool Qt_List_File::listFileAndDirectory( QDir dir) { bool ok = dir.exists(); //check if directory exist if ( ok ) { //set fileinfo filter QFileInfoList entries = dir.entryInfoList( QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files ); //loop over entries filter selected foreach ( QFileInfo entryInfo, entries ) { QString path = entryInfo.absoluteFilePath(); if ( entryInfo.isDir() ) //check if entryInfo is dir { if ( ! listFileAndDirectory( QDir( path ) ) ) { ui.plainTextReport->appendPlainText(path); ok = false; break; } ui.plainTextReport->appendPlainText(path); } else { ui.plainTextReport->appendPlainText(path); } } } if (ok && !dir.exists(dir.absolutePath())) ok = false; return ok; }
Output from this Qt List File And Directory program when searching all file and directory in my /home/toto directory.
You can try to searhing at your location by directory of file with this code. If you want to get the complete source code from this Qt List File And Directory program, please download at here.
Source : http://www.archivum.info/qt-interest@trolltech.com/2009-09/00049/Re-%28Qt-interest%29-What-should-I-use-to-delete-non-empty-directories.html