From c4e0b767338a63e797cdceb771358eb5aab8fc4f Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 3 Jun 2021 16:18:10 +0200 Subject: filter working --- musicopy.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/musicopy.c b/musicopy.c index 589aa80..3a85331 100644 --- a/musicopy.c +++ b/musicopy.c @@ -100,23 +100,23 @@ void fix_include_exclude(char*** listv, int listc) { } void copy(const char* path) { - printf("copying %s... to %s\n", path, target_music_dir); + printf("copying %s to %s...\n", path, target_music_dir); } int dir_callback(const char* path, const struct stat *sb, int tflag) { if (include_length > 0) { - bool allowed = false; + bool includes = false; for(int i = 0; i < include_length; i++) { - if(allowed) { - copy(path); - return 0; - } else { - allowed = fnmatch(exclude[i], path, 0) == 0; - } + includes = fnmatch(include[i], path, 0) == 0; + if(includes) break; } - return 0; + if (!includes) return 0; } + if (exclude_length > 0) + for(int i = 0; i < exclude_length; i++) + if(fnmatch(exclude[i], path, 0) == 0) return 0; + copy(path); return 0; @@ -155,7 +155,7 @@ int main() { print_opts(); - ftw(music_dir, dir_callback, 0); + ftw(music_dir, dir_callback, FTW_F); return 0; } -- cgit v1.2.3