summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2014-06-22 13:18:14 +1000
committerPaul Davis <paul@linuxaudiosystems.com>2014-06-25 12:40:10 -0400
commite7141d2b80d544cce74e93e41c150e0bf7c848b2 (patch)
tree914c41ac592292a027749ddc4792bd56a4d83607 /libs
parentab6837665f3973a793ddefb215887faa487cf13c (diff)
Add function to file_utils intended to be used internally
Diffstat (limited to 'libs')
-rw-r--r--libs/pbd/file_utils.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc
index f0c4433376..95a54c9a8b 100644
--- a/libs/pbd/file_utils.cc
+++ b/libs/pbd/file_utils.cc
@@ -63,6 +63,77 @@ using namespace std;
namespace PBD {
void
+run_functor_for_paths (vector<string>& result,
+ const Searchpath& paths,
+ bool (*functor)(const string &, void *),
+ void *arg,
+ bool pass_files_only,
+ bool pass_fullpath, bool return_fullpath,
+ bool recurse)
+{
+ for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
+ string expanded_path = path_expand (*i);
+ DEBUG_TRACE (DEBUG::FileUtils,
+ string_compose("Find files in expanded path: %1\n", expanded_path));
+
+ if (!Glib::file_test (expanded_path, Glib::FILE_TEST_IS_DIR)) continue;
+
+ try
+ {
+ Glib::Dir dir(expanded_path);
+
+ for (Glib::DirIterator di = dir.begin(); di != dir.end(); di++) {
+
+ string fullpath = Glib::build_filename (expanded_path, *di);
+ string basename = *di;
+
+ bool is_dir = Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR);
+
+ if (is_dir && recurse) {
+ DEBUG_TRACE (DEBUG::FileUtils,
+ string_compose("Descending into directory: %1\n",
+ fullpath));
+ run_functor_for_paths (result, fullpath, functor, arg, pass_files_only,
+ pass_fullpath, return_fullpath, recurse);
+ }
+
+ if (is_dir && pass_files_only) {
+ continue;
+ }
+
+ string functor_str;
+
+ if (pass_fullpath) {
+ functor_str = fullpath;
+ } else {
+ functor_str = basename;
+ }
+
+ DEBUG_TRACE (DEBUG::FileUtils,
+ string_compose("Run Functor using string: %1\n", functor_str));
+
+ if (!functor(functor_str, arg)) {
+ continue;
+ }
+
+ DEBUG_TRACE (DEBUG::FileUtils,
+ string_compose("Found file %1 matching functor\n", functor_str));
+
+ if (return_fullpath) {
+ result.push_back(fullpath);
+ } else {
+ result.push_back(basename);
+ }
+ }
+ }
+ catch (Glib::FileError& err)
+ {
+ warning << err.what() << endmsg;
+ }
+ }
+}
+
+void
get_directory_contents (const std::string& directory_path,
vector<string>& result,
bool files_only,