-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (73 loc) · 1.7 KB
/
main.cpp
File metadata and controls
82 lines (73 loc) · 1.7 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//To build:
// cl main.cpp /EHsc /FeRenameGuid.exe /link ole32.lib
#include <windows.h>
#include <stdio.h>
#include <string>
using namespace std;
void Recurse(string s,HANDLE h,WIN32_FIND_DATA* cd);
int main(int argc, char* argv[])
{
printf("Processing %s\n",argv[1]);
WIN32_FIND_DATA fd;
string s=argv[1];
s+="\\*.*";
HANDLE h=FindFirstFile(s.c_str(),&fd);
Recurse(argv[1],h,&fd);
}
void Recurse(string s,HANDLE h,WIN32_FIND_DATA* cd)
{
while(true)
{
if(!(cd->dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
{
char* start=cd->cFileName;
size_t size=strlen(start);
char* ptr=start+s.size()-1;
if(size>4 && !strcmpi(&start[size-4],".jpg"))
{
GUID guid = {0};
wchar_t szGuidW[40] = {0};
char szGuidA[40] = {0};
CoCreateGuid(&guid);
StringFromGUID2(guid, szGuidW, 40);
WideCharToMultiByte(0, 0, szGuidW, -1, szGuidA, 40, NULL, NULL);
string path(s);
path+="\\";
string newname=szGuidA;
path+=newname;
path+=".jpg";
string orig(s);
orig+="\\";
orig+=cd->cFileName;
printf("%s - %s\n",orig.c_str(),path.c_str());
rename(orig.c_str(),path.c_str());
}
}
else if(cd->dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{ //handle directory
if(strcmp(cd->cFileName,".") && strcmp(cd->cFileName,".."))
{
string s2=s;
s2+="\\";
s2+=cd->cFileName;
string s3=s2+"\\*.*";
WIN32_FIND_DATA cd2;
HANDLE h2=FindFirstFile(s3.c_str(),&cd2);
if(h2!=INVALID_HANDLE_VALUE)
{
Recurse(s2, h2, &cd2);
}
else
{/*
DWORD err=GetLastError();
printf("Recursion failed for %s - GetLastError==%d\n",s2.c_str(),err);*/
}
}
}
if(!FindNextFile(h,cd))
{
FindClose(h);
break;
}
}
}