pic32/libraries/SD/utility/SdFile.cpp
//------------------------------------------------------------------------------
/** Recursively delete a directory and all contained files.
 *
 * This is like the Unix/Linux 'rm -rf *' if called with the root directory
 * hence the name.
 *
 * Warning - This will remove all contents of the directory including
 * subdirectories.  The directory will then be removed if it is not root.
 * The read-only attribute for files will be ignored.
 *
 * \note This function should not be used to delete the 8.3 version of
 * a directory that has a long name.  See remove() and rmDir().
 *
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
Recursively delete a directory and all contained files.
This is like the Unix/Linux 'rm -rf *' if called with the root directory
hence the name.

This will remove all contents of the directory including
subdirectories.  The directory will then be removed if it is not root.
The read-only attribute for files will be ignored.

\note This function should not be used to delete the 8.3 version of
a directory that has a long name.  See remove() and rmDir().

\return The value one, true, is returned for success and
the value zero, false, is returned for failure.
Recursively delete a directory and all contained files . This is like the Unix / Linux ' rm - rf * ' if called with the root directory hence the name . This will remove all contents of the directory including subdirectories . The directory will then be removed if it is not root . The read - only attribute for files will be ignored . \ note This function should not be used to delete the 8 . 3 version of a directory that has a long name . See remove () and rmDir () . \ return The value one true is returned for success and the value zero false is returned for failure .
uint8_t SdFile::rmRfStar(void) {
  rewind();
  while (curPosition_ < fileSize_) {
    SdFile f;
    uint16_t index = curPosition_/32;
    dir_t* p = readDirCache();
    if (!p) return false;
    if (p->name[0] == DIR_NAME_FREE) break;
    if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') continue;
    if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;
    if (!f.open(this, index, O_READ)) return false;
    if (f.isSubDir()) {
      if (!f.rmRfStar()) return false;
    } else {
      f.flags_ |= O_WRITE;
      if (!f.remove()) return false;
    }
    if (curPosition_ != ((uint32_t) (32*(index + 1)))) {
      if (!seekSet(32*(index + 1))) return false;
    }
  }
  if (isRoot()) return true;
  return rmDir();
}
uint8_t SdFile :: rmRfStar ( void ) { rewind ( ) ; while ( curPosition_ < fileSize_ ) { SdFile f ; uint16_t index = curPosition_ / 32 ; dir_t * p = readDirCache ( ) ; if ( ! p ) return false ; if ( p -> name [ 0 ] == DIR_NAME_FREE ) break ; if ( p -> name [ 0 ] == DIR_NAME_DELETED || p -> name [ 0 ] == ' ' ) continue ; if ( ! DIR_IS_FILE_OR_SUBDIR ( p ) ) continue ; if ( ! f . open ( this , index , O_READ ) ) return false ; if ( f . isSubDir ( ) ) { if ( ! f . rmRfStar ( ) ) return false ; } else { f . flags_ |= O_WRITE ; if ( ! f . remove ( ) ) return false ; } if ( curPosition_ != ( ( uint32_t ) ( 32 * ( index + 1 ) ) ) ) { if ( ! seekSet ( 32 * ( index + 1 ) ) ) return false ; } } if ( isRoot ( ) ) return true ; return rmDir ( ) ; }
Recursively delete a directory and all contained files.
Recursively delete a directory and all contained files .
// remember position // done if past last entry // skip empty slot or '.' or '..' // skip if part of long file name or volume label in root // recursively delete // ignore read-only // position to next entry if required // don't try to delete root