In my application, I need to delete all the files in a folder as well as all the sub-directories.
I've looked at several discussions of this using API functions and quite frankly I understood very little of it. Using brute force and ignorance, I arrived at the following:

Qt Code:
  1. QStringList Clone::getFiles( const QString &path)
  2. {
  3. QDir dir( path);
  4. QStringList fileListing;
  5. foreach ( QString file, dir.entryList( QDir::Files))
  6. fileListing << QFileInfo( dir, file).absoluteFilePath();
  7.  
  8. foreach (QString subDir, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot))
  9. fileListing << getFiles( path + QDir::separator() + subDir);
  10.  
  11. return fileListing;
  12. }
To copy to clipboard, switch view to plain text mode 

I then deleted the files using:

Qt Code:
  1. int count = fileListing.size();
  2. for( i=0; i<count; i++)
  3. QFile::remove( fileListing[i]);
To copy to clipboard, switch view to plain text mode 

Flushed with success, I tackled the directories in the same way:

Qt Code:
  1. QStringList Clone::getDirs( const QString &path)
  2. {
  3. QDir dir( path);
  4. QStringList dirListing;
  5. foreach ( QString dirs, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot))
  6. dirListing << QFileInfo( dir, dirs).absoluteFilePath();
  7.  
  8. foreach (QString subDir, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot))
  9. dirListing << getDirs( path + QDir::separator() + subDir);
  10.  
  11. return dirListing;
  12. }
To copy to clipboard, switch view to plain text mode 

And attempted to delete them using:

Qt Code:
  1. int cnt = dirListing.size() - 1;
  2.  
  3. for( i = cnt; i = 0; i--)
  4. QDir::rmdir( dirListing[i]);
To copy to clipboard, switch view to plain text mode 

Got a compiler error for QDir::rmdir( ) need an object. Not clear why QDir acts different from QFile. Assume I need something like:

Qt Code:
  1. int cnt = dirListing.size() - 1;
  2.  
  3. for( i = cnt; i = 0; i--)
  4. dir.rmdir( dirListing[i]);
To copy to clipboard, switch view to plain text mode 

but have no idea how to define dir that will actually delete directories.