[Qt-interest] how to destroy a dir, no matter if any files in it or not.

Andre Somers andre at familiesomers.nl
Wed Mar 24 10:03:51 CET 2010


James Yan wrote:
> is any handy API do this?
>
> OR why my function fail to do that :
> //clear dir
> void myClearDir(QString strDir)
> {
> 	QDir dir(strDir);
>
> 	//clear the files
> 	QStringList fl = myListFiles(strDir,"*.*",true,false);
> 	for(int i=0;i<fl.size();i++)
> 	{
> 		dir.remove(fl.at(i));
> 	}
>
> 	//list dir and recall this func
> 	QStringList dl = myListDirs(strDir,true);
> 	for(int i=0;i<dl.size();i++)
> 	{
> 		myClearDir(dl.at(i));		
> 		dir.rmdir(dl.at(i));   // always return false, fail to delete the
> empty dir? why?
> 	}	
> }
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>   
A (dirty?) shortcut would be to use QProcess to call the system command 
for that. On windows, that would be `rmdir "c:\the directory\that will 
be\removed" /S`, on *nix systems `rm -rf "/the/path"` should do the trick.

André





More information about the Qt-interest-old mailing list