-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsearch.cpp
More file actions
23 lines (20 loc) · 805 Bytes
/
Copy pathsearch.cpp
File metadata and controls
23 lines (20 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "search.hpp"
#include "argparse.hpp"
int main(int argc, char const *argv[])
{
auto args = util::argparser("search files in command line (only for windows)");
args.set_program_name("search")
.add_option<std::string>("-d", "--dir", "sepcify directory", ".")
.add_argument("pattern", "search pattern")
.parse(argc, argv);
// 使用windows API获得完整路径
char *dir_name = new char[MAX_PATH];
SetCurrentDirectoryA(args.get_option<std::string>("--dir").c_str());
GetCurrentDirectoryA(MAX_PATH, dir_name);
std::string dir = dir_name;
if (dir.substr(2) == "\\")
dir = dir.substr(0, 2);
std::regex search_pattern(args.get_argument("pattern"), std::regex::icase);
search_file_with_regex(dir, search_pattern);
return 0;
}