-
Notifications
You must be signed in to change notification settings - Fork 1
/
dealAssetsFile.cpp
58 lines (49 loc) · 1.76 KB
/
dealAssetsFile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
处理重复的assets资源文件
*/
#include<iostream>
#include<io.h>
#include<string>
#include<vector>
#include <Windows.h>
using namespace std;
void getFiles(string path, vector<string>& files) {
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1) {
do {
//如果是目录,迭代之
if((fileinfo.attrib & _A_SUBDIR)) {
if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
getFiles( p.assign(path).append("\\").append(fileinfo.name), files );
} else { //如果不是,加入列表
files.push_back(fileinfo.name);
}
}while(_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
int main() {
string iterfilePath = "D:\\MY_DOCUMENT\\Work\\Leetcode\\Alog_Prefix\\assets"; // 迭代搜索路径
string delfilePath = "D:\\MY_DOCUMENT\\Work\\Leetcode\\Alog_TwoPointer\\assets"; // 待删除路径
vector<string> files; //存储文件名
// 获取 iter路径下的所有文件
getFiles(iterfilePath, files);
// 开删 del路径
int size = files.size(), delCnt = 0;
for (int i = 0; i < size; i++){
// cout << files[i] <<endl;
// cout << delfilePath + "\\" + files[i] << endl;
string filePath = delfilePath + "\\" + files[i];
auto res = DeleteFileA( filePath.c_str() ); // string > LPCSTR
if (res) {
cout << "Delete file:" << filePath << endl;
delCnt++;
}
}
cout << "Delete " << delCnt << " files" << endl;
return 0;
}