mardi 26 juin 2018

Process files in folders and keep the structure with the output

I've got the following problem. I have the following code:

static void performtask_dir(const char *path) {
    struct dirent *entry;
    DIR *dir = opendir(path);
    if (dir == NULL) {
        return;
    }
    while ((entry = readdir(dir)) != NULL) {
      if (strcmp(entry-> d_name, ".") && strcmp(entry->d_name,".."))
        performTask(std::string(entry->d_name));
        //printf("%s\n",entry->d_name);
    }
    closedir(dir);
}


int main() {
  performtask_dir("./data");
}

and also in performTask I have something like this:

void performTask(...) {
...
file->Export("./output");
...
}

That works fine, but it takes all the documents on the input folder and puts them in the output folder. Now I have a folder with sub-folders, and I would like to do the same but keeping the structure of sub-folders. For instance, if in the input folder I have dir1, dir2 and dir3, I would like to have the output folder with dir1, dir2 and dir3 (each one with the output documents). Is there an easy way to achieve this? Thanks!

Aucun commentaire:

Enregistrer un commentaire