Category: PHP, PHP

There are lot of useful inbuilt functions that comes with PHP interpreter. One such function is rmdir which allows us to delete a folder/directory through PHP code.

As useful this function is, it fails to delete a directory when the directory is not empty throwing a warning message Directory not empty. As a workaround, we need to first delete all files and folders recursively inside the specified directory and then delete the directory itself.

Here, we are passing RecursiveIteratorIterator::CHILD_FIRST as mode to get the children of the directory before getting the directory name itself.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners