-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_operations.cpp
58 lines (44 loc) · 1.54 KB
/
file_operations.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
#include <Windows.h>
#include <iostream>
#include "WPDException.h"
#include "WPDObject.h"
#include "WPDDevice.h"
#include "WPDObjectIterator.h"
using namespace std;
using namespace WPD;
static const wstring someDevicePath = L"";
static const wstring someFilePath = L"o91909EF2";
void file_operations() {
try {
WPDDevice device(someDevicePath);
WPDObject file = device.getObject(someFilePath);
// Copy file to PC without dates
// device.downloadFile(L"o91909EF2", L"C:\\MyFolder\\123.txt");
// or copy file to PC with dates
SYSTEMTIME created = file.getFileDateCreated();
SYSTEMTIME modified = file.getFileDateModified();
device.downloadFile(file.getPath(), L"C:\\MyFolder\\" + file.getFileName(), created, modified);
// Or read file to buffer (it is not an ASCII string)
string buffer = device.readFile(file.getPath());
// Or do something with file
int part = 0;
device.readFile(file.getPath(), 1024, [&part](const char *buf, uint32_t size) {
string filePart{buf, size};
cout << "File part #" << part << endl;
cout << filePart.c_str() << endl;
part++;
});
}
catch (WPDException &e) {
cout << "Error: " << e.what() << endl;
cout << "HRESULT: " << (void *) e.code() << " - " << e.explain() << endl;
}
}
int main() {
setlocale(0, "");
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
file_operations();
CoUninitialize();
system("pause");
return 0;
}