diff options
author | 2015-11-06 16:27:58 -0800 | |
---|---|---|
committer | 2015-11-06 16:27:58 -0800 | |
commit | f41959ccb2d9d4c722fe8fc3351401d53bcf4900 (patch) | |
tree | ef0ca22cb2a5ac4bdec9d080d8e0788a53ed496d /tensorflow/core/lib/io/match.cc |
TensorFlow: Initial commit of TensorFlow library.
TensorFlow is an open source software library for numerical computation
using data flow graphs.
Base CL: 107276108
Diffstat (limited to 'tensorflow/core/lib/io/match.cc')
-rw-r--r-- | tensorflow/core/lib/io/match.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tensorflow/core/lib/io/match.cc b/tensorflow/core/lib/io/match.cc new file mode 100644 index 0000000000..1563642d0b --- /dev/null +++ b/tensorflow/core/lib/io/match.cc @@ -0,0 +1,31 @@ +#include "tensorflow/core/lib/io/match.h" +#include <fnmatch.h> +#include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/public/env.h" + +namespace tensorflow { +namespace io { + +Status GetMatchingFiles(Env* env, const string& pattern, + std::vector<string>* results) { + results->clear(); + std::vector<string> all_files; + string dir = Dirname(pattern).ToString(); + if (dir.empty()) dir = "."; + string basename_pattern = Basename(pattern).ToString(); + Status s = env->GetChildren(dir, &all_files); + if (!s.ok()) { + return s; + } + for (const auto& f : all_files) { + int flags = 0; + if (fnmatch(basename_pattern.c_str(), Basename(f).ToString().c_str(), + flags) == 0) { + results->push_back(JoinPath(dir, f)); + } + } + return Status::OK(); +} + +} // namespace io +} // namespace tensorflow |