#include <QtCore/QFile>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
using namespace std;
void deleteDirectory(const QString &sPath)
{
QFileInfo fileList(sPath);
if(fileList.isDir())
{
int sonFileCount =0;
QDir thisDir(sPath);
sonFileCount = thisDir.entryInfoList().count();
QFileInfoList newFileList = thisDir.entryInfoList();
if(sonFileCount>2)
{
for(int i=0;i<sonFileCount;i++)
{
if(newFileList.at(i).fileName().operator ==(".")|newFileList.at(i).fileName().operator ==(".."))
{
continue;
}
deleteDirectory(newFileList.at(i).filePath());
}
}
fileList.absoluteDir().rmpath(fileList.fileName());
}
else if(fileList.isFile())
{
fileList.absoluteDir().remove(fileList.fileName());
}
}
void main()
{
deleteDirectory("D:/test");
}
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
using namespace std;
void deleteDirectory(const QString &sPath)
{
QFileInfo fileList(sPath);
if(fileList.isDir())
{
int sonFileCount =0;
QDir thisDir(sPath);
sonFileCount = thisDir.entryInfoList().count();
QFileInfoList newFileList = thisDir.entryInfoList();
if(sonFileCount>2)
{
for(int i=0;i<sonFileCount;i++)
{
if(newFileList.at(i).fileName().operator ==(".")|newFileList.at(i).fileName().operator ==(".."))
{
continue;
}
deleteDirectory(newFileList.at(i).filePath());
}
}
fileList.absoluteDir().rmpath(fileList.fileName());
}
else if(fileList.isFile())
{
fileList.absoluteDir().remove(fileList.fileName());
}
}
void main()
{
deleteDirectory("D:/test");
}