Page 1 of 1

Delete folder and contents?

Posted: Wed Feb 13, 2019 7:20 pm
by gunar.kroeger
Hi,
I wish to remove directory and and its contents like rm -rf <target> from SD card

I found this example:
  1. #define _XOPEN_SOURCE 500
  2. #include <stdio.h>
  3. #include <ftw.h>
  4. #include <unistd.h>
  5.  
  6. int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
  7. {
  8.     int rv = remove(fpath);
  9.  
  10.     if (rv)
  11.         perror(fpath);
  12.  
  13.     return rv;
  14. }
  15.  
  16. int rmrf(char *path)
  17. {
  18.     return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
  19. }
But I get "fatal error: ftw.h: No such file or directory" even though I'm defining _XOPEN_SOURCE 500.
I tried to define XOPEN_SOURCE as

Code: Select all

CFLAGS := -D_OXPEN_SOURCE=500
in the project Makefile, but that caused a lot of other idf components compilation errors.

Re: Delete folder and contents?

Posted: Wed Feb 13, 2019 10:50 pm
by chegewara
CFLAGS := -D_OXPEN_SOURCE=500
Typo on forum or in code?

Re: Delete folder and contents?

Posted: Thu Feb 14, 2019 3:04 am
by ESP_Sprite
I don't think our newlib implements nftw; it was a pretty recent addition to their codebase. Suggest you use the 'classic' opendir/readdir calls instead, and do the recursion yourself.

Re: Delete folder and contents?

Posted: Thu Feb 14, 2019 1:33 pm
by gunar.kroeger
Typo on forum or in code?
sorry, on forum.
Suggest you use the 'classic' opendir/readdir calls instead, and do the recursion yourself.
Ok. Thanks for the quick reply (: