#include <bits/stdc++.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
typedef long long LL;
unordered_set<string> postfix;
unordered_set<string> files;
bool flg = false;
bool TraverseDirectory(string path)
{
LL Handle;
struct __finddata64_t FileInfo;
string strFind = path + "\\*";
if ((Handle = _findfirst64(strFind.c_str(), &FileInfo)) == -1L)
{
printf("没有找到匹配的项目\n");
return false;
}
do
{
if (FileInfo.attrib & _A_SUBDIR)
{
if ((strcmp(FileInfo.name, ".") != 0) && (strcmp(FileInfo.name, "..") != 0))
{
string newPath = path + "\\" + FileInfo.name;
TraverseDirectory(newPath);
}
}
else
{
flg = true;
files.insert(path);
}
} while (_findnext64(Handle, &FileInfo) == 0);
_findclose(Handle);
return true;
}
void color(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
int main()
{
postfix.insert("(1).txt");
postfix.insert("(1).doc");
postfix.insert("(1).docx");
postfix.insert("(1).zip");
postfix.insert("(1).ppt");
postfix.insert("(1).pptx");
postfix.insert("(1).pdf");
cout << "输入文件路径:" << endl;
string path = "";
getline(cin, path);
files.insert(path);
if(TraverseDirectory(path) && flg)
{
for(auto &f : files)
{
if(f == ""){
color(4);
cout << "执行出错!!!" << endl;
return -1;
}
for(auto& s : postfix)
{
string del = "del " + string(1,'\"') + f + string(1,'\\')+ "\\*" + s + '"';
char *delc=(char*)del.c_str();
system(delc);
}
}
color(2);
cout <<"删除成功!!!"<<endl;
}
else
{
color(4);
cout << "无重复或者执行失败:可能原因文件名存在特殊字符(空格)!!!" <<endl;
}
system("pause");
return 0;
}