Skip to content

Commit

Permalink
Filesystem::safeScandir()
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Battis committed Feb 14, 2024
1 parent 2c4453c commit a1a059c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ private static function recursiveDelete(string $path)
if (!is_dir($path)) {
return unlink($path);
} elseif (is_dir($path)) {
foreach (scandir($path) as $item) {
if ($item !== "." && $item !== "..") {
Filesystem::recursiveDelete(Path::join($path, $item));
}
foreach (Filesystem::safeScandir($path) as $item) {
Filesystem::recursiveDelete(Path::join($path, $item));
}
return rmdir($path);
}
}

public static function safeScandir(string $path)
{
return array_values(array_diff(scandir($path), [".", ".."]));
}
}

0 comments on commit a1a059c

Please sign in to comment.