-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_pic.cpp
72 lines (63 loc) · 1.91 KB
/
get_pic.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <windows.h>
#include <Lmcons.h>
#include <shellapi.h>
#include <tchar.h>
#pragma comment(lib, "shell32.lib")
using namespace std;
int main()
{
//get local username in windows
char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);
string UserName(username);
vector<string> files;
DIR *pic_dir; //picture directory
DIR *dest_dir; // destination directory
struct dirent *dirp;
string source = "C:\\Users\\"+UserName+"\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets";
string dest = "C:\\Users\\"+UserName+"\\Desktop\\picture";
mkdir(dest.c_str());
if((pic_dir = opendir(source.c_str())) == NULL )
{
cout << "Cannot find pictures in Windows Spotlight." << endl ;
cout << "Error(" << errno << ") opening " << pic_dir << endl;
}
if((dest_dir = opendir(dest.c_str())) == NULL )
{
cout << "Error(" << errno << ") opening " << dest_dir << endl;
}
//copy picture from sys to dest
string to = dest+"\0" ;
string from = source+"\\*\0" ;
SHFILEOPSTRUCT fop;
ZeroMemory(&fop, sizeof(fop));
fop.wFunc = FO_COPY;
fop.pTo = _T(to.c_str());
fop.pFrom = _T(from.c_str());
SHFileOperation(&fop);
while((dirp = readdir(dest_dir)) != NULL )
{
files.push_back(string(dirp->d_name));
}
closedir(pic_dir);
closedir(dest_dir);
for(int i = 0; i < files.size() ; i++){
// cout << files[i] << endl ;
string oldname = dest + "\\" + files[i] ;
string temp = dest + "\\" + to_string(i) + ".jpg";
cout << temp <<endl ;
const char* newname = temp.c_str();
rename(oldname.c_str(),newname);
}
cout << "\n已在桌面建立資料夾picture" << endl ;
cout << "複製完成......" << endl;
cout << "\n要重新執行前,先刪除picture 資料夾。" << endl;
cout << "按任意建結束......" << endl ;
cin.get();
}