forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.hpp
More file actions
94 lines (76 loc) · 2.06 KB
/
Copy pathutil.hpp
File metadata and controls
94 lines (76 loc) · 2.06 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
#ifndef _AV_TRANSCODER_PROFILE_UTIL_HPP_
#define _AV_TRANSCODER_PROFILE_UTIL_HPP_
#if defined(__LINUX__)
#define DIRLIST_SEP_CHARS ":;"
#define DIRSEP "/"
#include <dirent.h>
#elif defined(__MACOS__)
#define DIRLIST_SEP_CHARS ";:"
#define DIRSEP "/"
#include <dirent.h>
#elif defined(__WINDOWS__)
#define DIRLIST_SEP_CHARS ";"
#define DIRSEP "\\"
// CINTERFACE needs to be declared if compiling with VC++
#include <shlobj.h>
#include <tchar.h>
#ifndef _MSC_VER
#define SHGFP_TYPE_CURRENT 0
#endif
#endif
#include <string>
#include <cstring>
#include <iostream>
namespace avtranscoder
{
void split(std::vector<std::string>& splitString, const std::string& inputString, const std::string& splitChars)
{
char* part = strtok(const_cast<char*>(inputString.c_str()), splitChars.c_str());
while(part != NULL)
{
splitString.push_back(std::string(part));
part = strtok(NULL, splitChars.c_str());
}
}
int getFilesInDir(const std::string& dir, std::vector<std::string>& files)
{
#if defined(__WINDOWS__)
WIN32_FIND_DATA findData;
HANDLE findHandle;
findHandle = FindFirstFile((dir + "\\*").c_str(), &findData);
if(findHandle == INVALID_HANDLE_VALUE)
{
return -1;
}
while(1)
{
const std::string filename(findData.cFileName);
bool isdir = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
if(!isdir && filename.find(".prf") != std::string::npos)
files.push_back(filename);
int rval = FindNextFile(findHandle, &findData);
if(rval == 0)
break;
}
#else
DIR* dp;
struct dirent* dirp;
if((dp = opendir(dir.c_str())) == NULL)
{
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
return errno;
}
while((dirp = readdir(dp)) != NULL)
{
const std::string filename(dirp->d_name);
if(filename == "." || filename == "..")
continue;
if(filename.find(".prf") != std::string::npos)
files.push_back(filename);
}
closedir(dp);
#endif
return 0;
}
}
#endif