Jump to main content Jump to doc navigation

xPDOCacheManager::deleteTree

Recursively deletes a directory tree of files.

The options array has the following parameters available:

  • deleteTop - If true, will delete the top directory that is specified. Defaults to false.
  • skipDirs - If true, will not delete the directories; just the files. Defaults to false.
  • extensions - An array of file extensions to filter by - will only delete files with those extensions. Set to null or false to delete all files.
  • delete_exclude_items - An array of names of files to skip.
  • delete_exclude_patterns - An array or string of patterns to exclude by.

Syntax

API Docs: http://api.modxcms.com/xpdo/cache/xPDOCacheManager.html#deleteTree

boolean deleteTree (string $dirname, [array $options = array(
   'deleteTop' => false,
   'skipDirs' => false,
   'extensions' => array('.cache.php')
)])

Example

Delete the /modx/assets/videos/ directory (assuming the constant MODX_ASSETS_PATH is set) and all the files in it:

$xpdo->cacheManager->deleteTree(MODX_ASSETS_PATH.'videos/',array(
   'deleteTop' => true,
   'extensions' => false,
));

Delete only .flv files in the above directory:

$xpdo->cacheManager->deleteTree(MODX_ASSETS_PATH.'videos/',array(
   'deleteTop' => true,
   'extensions' => array('.flv'),
));

Delete all movies in above directory, except george.mov, buddies.flv, and any file name containing the word 'fun'.

$xpdo->cacheManager->deleteTree(MODX_ASSETS_PATH.'videos/',array(
   'deleteTop' => true,
   'extensions' => false,
   'delete_exclude_items' => array('george.mov','buddies.flv'),
   'delete_exclude_patterns' => '/fun/i',
));

See Also

  1. xPDOCacheManager.copyFile
  2. xPDOCacheManager.copyTree
  3. xPDOCacheManager.delete
  4. xPDOCacheManager.deleteTree
  5. xPDOCacheManager.endsWith
  6. xPDOCacheManager.escapeSingleQuotes
  7. xPDOCacheManager.get
  8. xPDOCacheManager.getCachePath
  9. xPDOCacheManager.getCacheProvider
  10. xPDOCacheManager.matches
  11. xPDOCacheManager.replace
  12. xPDOCacheManager.writeFile
  13. xPDOCacheManager.set
  14. xPDOCacheManager.writeTree
  15. xPDOCacheManager

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more