-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibretta_utils.cpp
85 lines (63 loc) · 1.46 KB
/
libretta_utils.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
73
74
75
76
77
78
79
80
81
82
83
84
85
/***********************************************************
* this code by Peter Semiletov is Public Domain *
**********************************************************/
#include <iostream>
#include <locale>
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h> // for FILENAME_MAX
#include <dirent.h>
#ifdef WINDOWS
#include <direct.h>
#define get_cur_dir _getcwd
#else
#include <unistd.h>
#define get_cur_dir getcwd
#endif
using namespace std;
string get_2char_locale()
{
locale l("");
string nm = l.name();
string nn;
nn += nm[0];
nn += nm[1];
return nn;
}
string get_home_dir()
{
string homedir = getenv ("HOME");
return homedir;
}
string current_path()
{
char path [FILENAME_MAX];
string result;
if (! get_cur_dir (path, sizeof (path)))
return result;
result = path;
return result;
}
vector <string> files_get_list (const string &path, const string &ext) //ext with dot: ".txt"
{
DIR *directory;
struct dirent *dir_entry;
vector <string> result;
directory = opendir (path.c_str());
if (! directory)
{
closedir (directory);
return result;
}
while (dir_entry = readdir (directory))
{
// std::cout << dir_entry->d_name << std::endl;
string t = dir_entry->d_name;
if (t.rfind (ext) != string::npos)
result.push_back (path + "/" + t);
}
closedir (directory);
return result;
}