如果dir中有一些文件test.txt, test2.txt, test3.txt
,则可以使用cmd命令删除所有文件
del test*.txt
QT C++
不使用时如何做system()
我试过了
QFile("test*.txt").remove();
但它不起作用。
主要任务是过滤文件,以便我们可以使用QDir
,nameFilter
如下所示:
QDir dir("/path/of/directory", {"test*.txt"});
for(const QString & filename: dir.entryList()){
dir.remove(filename);
}
或使用QDirIterator:
QDirIterator it("/path/of/directory", {"test*.txt"});
while (it.hasNext())
QFile(it.next()).remove();
//QDir().remove(it.next());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句