blob: 06a0b2086ad87d691d41013db1585b5886f210ce (
plain)
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
|
#ifndef SLANG_DIRECTORY_UTIL_H
#define SLANG_DIRECTORY_UTIL_H
#include "../../source/core/slang-io.h"
class CombinePathVisitor : public Slang::Path::Visitor
{
public:
virtual void accept(Slang::Path::Type type, const Slang::UnownedStringSlice& filename)
SLANG_OVERRIDE
{
using namespace Slang;
const Path::TypeFlags flags = Path::TypeFlags(1) << int(type);
if (flags & m_allowedFlags)
{
m_paths.add(Path::combine(m_directoryPath, filename));
}
}
/// Ctor
CombinePathVisitor(const Slang::String& directoryPath, Slang::Path::TypeFlags allowedFlags)
: m_directoryPath(directoryPath), m_allowedFlags(allowedFlags)
{
}
Slang::List<Slang::String> m_paths;
protected:
Slang::Path::TypeFlags m_allowedFlags;
Slang::String m_directoryPath;
};
/* A helper class for finding the contents of directories */
class DirectoryUtil
{
public:
/// Enumerate subdirectories in the given `directoryPath`, storing in outPaths.
/// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
static SlangResult findDirectories(
const Slang::String& directoryPath,
Slang::List<Slang::String>& outPaths);
/// Enumerate files in the given `directoryPath` that match the provided
/// `pattern` as a simplified regex for files to return (e.g., "*.txt")
/// Note that the specifics of the pattern matching are *target specific*
/// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
static SlangResult findFilesMatchingPattern(
const Slang::String& directoryPath,
const char* pattern,
Slang::List<Slang::String>& outPaths);
/// Enumerate files in the given `directoryPath`, storing in outPaths.
/// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
static SlangResult findFiles(
const Slang::String& directoryPath,
Slang::List<Slang::String>& outPaths);
};
#endif // SLANG_DIRECTORY_UTIL_H
|