-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
332 lines (309 loc) · 11.5 KB
/
Copy pathmain.cpp
File metadata and controls
332 lines (309 loc) · 11.5 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
path p (".");
if (is_directory(p))
{
cout << p << " is a directory containing:\n";
std::vector<path> v;
for (auto&& x : directory_iterator(p))
v.push_back(x.path());
std::sort(v.begin(), v.end());
for (auto&& x : v)
cout << " " << x.filename() << '\n';
}
return 0;
}
/*
#include <exiv2/exiv2.hpp>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <string>
#include <algorithm>
#include <filesystem>
//added because the program needs c++-17 for the filesystem library but auto_ptr is deprecated in c++-17
#define std::unique_ptr auto_ptr
#if defined(EXV_UNICODE_PATH) && defined(__MINGW__)
#undef EXV_UNICODE_PATH
#endif
#ifdef EXV_UNICODE_PATH
#define _tchar wchar_t
#define _tstrcmp wcscmp
#define _t(s) L##s
#define _tcout wcout
#define _tmain wmain
#else
#define _tchar char
#define _tstrcmp strcmp
#define _t(s) s
#define _tcout cout
#define _tmain main
#endif
int func(std::string fileName)
{
try
{
/*
const _tchar* prog = argv[0];
const _tchar* file = argv[1];
if (argc != 2)
{
std::_tcout << _t("Usage: ") << prog << _t(" [ file | --version || --version-test ]") << std::endl;
return 1;
}
if ( _tstrcmp(file,_t("--version")) == 0 )
{
exv_grep_keys_t keys;
Exiv2::dumpLibraryInfo(std::cout,keys);
return 0;
}
else if ( _tstrcmp(file,_t("--version-test")) == 0 )
{
// verifies/test macro EXIV2_TEST_VERSION
// described in include/exiv2/version.hpp
std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl
<< "Exiv2::version() " << Exiv2::version() << std::endl
<< "strlen(Exiv2::version()) " << ::strlen(Exiv2::version()) << std::endl
<< "Exiv2::versionNumber() " << Exiv2::versionNumber() << std::endl
<< "Exiv2::versionString() " << Exiv2::versionString() << std::endl
<< "Exiv2::versionNumberHexString() " << Exiv2::versionNumberHexString() << std::endl
;
// Test the Exiv2 version available at runtime but compile the if-clause only if
// the compile-time version is at least 0.15. Earlier versions didn't have a
// testVersion() function:
#if EXIV2_TEST_VERSION(0,15,0)
if (Exiv2::testVersion(0,13,0))
{
std::cout << "Available Exiv2 version is equal to or greater than 0.13\n";
}
else
{
std::cout << "Installed Exiv2 version is less than 0.13\n";
}
#else
std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n";
#endif
return 0;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fileName);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty())
{
std::string error("No Exif data found in file");
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
}
Exiv2::ExifData::const_iterator end = exifData.end();
for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
{
const char* tn = i->typeName();
std::cout << std::setw(44) << std::setfill(' ') << std::left
<< i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << i->tag() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< (tn ? tn : "Unknown") << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< i->count() << " "
<< std::dec << i->value()
<< "\n";
}
return 0;
}
//catch (std::exception& e) {
//catch (Exiv2::AnyError& e) {
catch (Exiv2::Error& e)
{
std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
return -1;
}
}
//namespace fs = std::filesystem;
int _tmain(int argc, _tchar* const argv[]) {
std::string path = std::filesystem::current_path();
//path += "/pics";
std::cout << path << std::endl << std::endl;
int numInt = 0;
for (const auto & entry : std::filesystem::directory_iterator(path))
{
std::string fileName1 = entry.path();//.filename();
std::string fileName2 = fileName1;
std::transform(fileName2.begin(), fileName2.end(), fileName2.begin(), ::tolower);
//std::string fileName2 = fs::file_status();//entry.path().extension();
std::cout << fileName1 << std::endl;
if(fileName2.rfind(".jpg")!=-1)
{
func(fileName2);
std::string numString = std::to_string(numInt);
while(numString.length() < 4)
{
numString = "0" + numString;
}
std::cout << std::rename(fileName1.c_str(), (path + "/DSCN" + numString + ".jpg").c_str()) << std::endl;
std::cout << (path + "/DSCN" + numString + ".JPG").c_str() << std::endl;
numInt++;
}
else if(fileName2.rfind(".png")!=-1)
{
std::string numString = std::to_string(numInt);
while(numString.length() < 4)
{
numString = "0" + numString;
}
std::cout << std::rename(fileName1.c_str(), (path + "/DSCN" + numString + ".PNG").c_str()) << std::endl;
numInt++;
}
else
{
std::cout << "This file does not have a jpg or png file extension." << std::endl;
}
std::cout << std::endl;
//std::cout << entry.path().filename() << std::endl;
}
}
*/
/*
#include <exiv2/exiv2.hpp>
#include <iostream>
#include <iomanip>
#include <cassert>
#if defined(EXV_UNICODE_PATH) && defined(__MINGW__)
#undef EXV_UNICODE_PATH
#endif
#ifdef EXV_UNICODE_PATH
#define _tchar wchar_t
#define _tstrcmp wcscmp
#define _t(s) L##s
#define _tcout wcout
#define _tmain wmain
#else
#define _tchar char
#define _tstrcmp strcmp
#define _t(s) s
#define _tcout cout
#define _tmain main
#endif
int _tmain(int argc, _tchar* const argv[])
try {
const _tchar* prog = argv[0];
const _tchar* file = argv[1];
if (argc != 2) {
std::_tcout << _t("Usage: ") << prog << _t(" [ file | --version || --version-test ]") << std::endl;
return 1;
}
if ( _tstrcmp(file,_t("--version")) == 0 ) {
exv_grep_keys_t keys;
Exiv2::dumpLibraryInfo(std::cout,keys);
return 0;
} else if ( _tstrcmp(file,_t("--version-test")) == 0 ) {
// verifies/test macro EXIV2_TEST_VERSION
// described in include/exiv2/version.hpp
std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl
<< "Exiv2::version() " << Exiv2::version() << std::endl
<< "strlen(Exiv2::version()) " << ::strlen(Exiv2::version()) << std::endl
<< "Exiv2::versionNumber() " << Exiv2::versionNumber() << std::endl
<< "Exiv2::versionString() " << Exiv2::versionString() << std::endl
<< "Exiv2::versionNumberHexString() " << Exiv2::versionNumberHexString() << std::endl
;
// Test the Exiv2 version available at runtime but compile the if-clause only if
// the compile-time version is at least 0.15. Earlier versions didn't have a
// testVersion() function:
#if EXIV2_TEST_VERSION(0,15,0)
if (Exiv2::testVersion(0,13,0)) {
std::cout << "Available Exiv2 version is equal to or greater than 0.13\n";
} else {
std::cout << "Installed Exiv2 version is less than 0.13\n";
}
#else
std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n";
#endif
return 0;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
std::string error("No Exif data found in file");
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
}
Exiv2::ExifData::const_iterator end = exifData.end();
for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
const char* tn = i->typeName();
std::cout << std::setw(44) << std::setfill(' ') << std::left
<< i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << i->tag() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< (tn ? tn : "Unknown") << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< i->count() << " "
<< std::dec << i->value()
<< "\n";
}
return 0;
}
//catch (std::exception& e) {
//catch (Exiv2::AnyError& e) {
catch (Exiv2::Error& e) {
std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
return -1;
}
*/
/*
#include <string>
#include <iostream>
#include <algorithm>
#include <filesystem>
//namespace fs = std::filesystem;
int main() {
std::string path = std::filesystem::current_path();
//path += "/pics";
std::cout << path << std::endl << std::endl;
int numInt = 0;
for (const auto & entry : std::filesystem::directory_iterator(path))
{
std::string fileName1 = entry.path();//.filename();
std::string fileName2 = fileName1;
std::transform(fileName2.begin(), fileName2.end(), fileName2.begin(), ::tolower);
//std::string fileName2 = fs::file_status();//entry.path().extension();
std::cout << fileName1 << std::endl;
if(fileName2.rfind(".jpg")!=-1)
{
std::string numString = std::to_string(numInt);
while(numString.length() < 4)
{
numString = "0" + numString;
}
std::cout << std::rename(fileName1.c_str(), (path + "/DSCN" + numString + ".jpg").c_str()) << std::endl;
std::cout << (path + "/DSCN" + numString + ".JPG").c_str() << std::endl;
numInt++;
}
else if(fileName2.rfind(".png")!=-1)
{
std::string numString = std::to_string(numInt);
while(numString.length() < 4)
{
numString = "0" + numString;
}
std::cout << std::rename(fileName1.c_str(), (path + "/DSCN" + numString + ".PNG").c_str()) << std::endl;
numInt++;
}
else
{
std::cout << "This file does not have a jpg or png file extension." << std::endl;
}
std::cout << std::endl;
//std::cout << entry.path().filename() << std::endl;
}
}
*/