From ebfbc1144c93417467c159172b6458437948857f Mon Sep 17 00:00:00 2001 From: Tuan PM Date: Thu, 12 Jan 2017 19:57:50 +0700 Subject: [PATCH] Process recursive folder for spiffs images (#320) * Process rercursive folder for spiffs images * Flat file name from the directory structure * change method to find '/' as the suggestion of @sheinz * remove unused variable --- extras/spiffs/mkspiffs/mkspiffs.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/extras/spiffs/mkspiffs/mkspiffs.c b/extras/spiffs/mkspiffs/mkspiffs.c index 85fb35f..9ed6a7d 100644 --- a/extras/spiffs/mkspiffs/mkspiffs.c +++ b/extras/spiffs/mkspiffs/mkspiffs.c @@ -178,7 +178,7 @@ static bool process_directory(const char *direcotry) { DIR *dp; struct dirent *ep; - char path[256]; + char path[256], *filename; dp = opendir(direcotry); if (dp != NULL) { @@ -187,12 +187,22 @@ static bool process_directory(const char *direcotry) !strcmp(ep->d_name, "..")) { continue; } + if(ep->d_type == DT_DIR) { + char *new_dir_name = malloc(strlen(direcotry) + strlen(ep->d_name) + 2); + sprintf(new_dir_name, "%s/%s", direcotry, ep->d_name); + process_directory(new_dir_name); + free(new_dir_name); + continue; + } if (ep->d_type != DT_REG) { continue; // not a regular file } sprintf(path, "%s/%s", direcotry, ep->d_name); - printf("Processing file %s\n", path); - if (!process_file(path, ep->d_name)) { + filename = strchr(path, '/'); + filename = filename ? &filename[1] : path; + + printf("Processing file source %s, dest: %s\n", path, filename); + if (!process_file(path, filename)) { printf("Error processing file\n"); break; }