Delete folder and contents?

User avatar
gunar.kroeger
Posts: 143
Joined: Fri Jul 27, 2018 6:48 pm

Delete folder and contents?

Postby gunar.kroeger » Wed Feb 13, 2019 7:20 pm

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.
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Delete folder and contents?

Postby chegewara » Wed Feb 13, 2019 10:50 pm

CFLAGS := -D_OXPEN_SOURCE=500
Typo on forum or in code?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Delete folder and contents?

Postby ESP_Sprite » Thu Feb 14, 2019 3:04 am

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.

User avatar
gunar.kroeger
Posts: 143
Joined: Fri Jul 27, 2018 6:48 pm

Re: Delete folder and contents?

Postby gunar.kroeger » Thu Feb 14, 2019 1:33 pm

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 (:
"Running was invented in 1612 by Thomas Running when he tried to walk twice at the same time."

Who is online

Users browsing this forum: No registered users and 180 guests