LoginSignup
6
6

More than 3 years have passed since last update.

ディレクトリ内のファイルの消去

Last updated at Posted at 2018-12-17

globでファイルのみを消去

array_map('unlink', glob("path/to/dir/*.php"));

イテレーターでファイルとディレクトリを消去

foreach (new RecursiveIteratorIterator(new \RecursiveDirectoryIterator('path/to/dir', \FilesystemIterator::SKIP_DOTS),RecursiveIteratorIterator::CHILD_FIRST) as $file) {
    $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6