Oihana PHP

deleteTemporaryDirectory.php

Table of Contents

Functions

deleteTemporaryDirectory()  : bool
Deletes a directory located in the system temporary folder (recursively).

Functions

deleteTemporaryDirectory()

Deletes a directory located in the system temporary folder (recursively).

deleteTemporaryDirectory(string|array<string|int, string>|null $path[, bool $assertable = true ][, bool $isReadable = true ][, bool $isWritable = true ]) : bool

The given $path is appended to sys_get_temp_dir() in the same way as getTemporaryDirectory():

  • null → sys temp dir itself,
  • 'logs' → "/tmp/logs",
  • ['my', 'app'] → "/tmp/my/app".
Parameters
$path : string|array<string|int, string>|null

Optional sub‑path(s) inside sys_get_temp_dir().

$assertable : bool = true

Whether to validate the composed directory before deletion. Defaults to true.

$isReadable : bool = true

Check readability (passed to assertDirectory()). Defaults to true.

$isWritable : bool = true

Check writability (passed to assertDirectory()). Defaults to true.

Tags
throws
DirectoryException

If validation/deletion fails.

example
use function oihana\files\deleteTemporaryDirectory;

// Remove /tmp/old_reports (et son contenu)
deleteTemporaryDirectory('old_reports');

// Remove /tmp/tmp123/cache/images
deleteTemporaryDirectory(['tmp123', 'cache', 'images']);

// Force failure if folder is not writable
deleteTemporaryDirectory('protected_dir', isWritable: true);
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

True if the directory was deleted or did not exist.


        
On this page

Search results