终于实现啦,虽然不是我写的,但是还是分享一下:
void file::deleteDirectory(QFileInfo fileList){
if(fileList.isDir()){
int childCount =0;
QString dir = fileList.filePath();
QDir thisDir(dir);
childCount = thisDir.entryInfoList().count();
QFileInfoList newFileList = thisDir.entryInfoList();
if(childCount>2){
for(int i=0;i<childCount;i++){
if(newFileList.at(i).fileName().operator ==(".")|newFileList.at(i).fileName().operator ==("..")){
continue;
}
deleteDirectory(newFileList.at(i));
}
}
fileList.absoluteDir().rmpath(fileList.fileName());
}else if(fileList.isFile()){
fileList.absoluteDir().remove(fileList.fileName());
}