-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.php
More file actions
49 lines (39 loc) · 936 Bytes
/
cleanup.php
File metadata and controls
49 lines (39 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
$filesToRemove = [
'README.md',
'resources/images/users-table.png',
'resources/images/tests.png',
'resources/images/login-page.png',
'resources/images',
__FILE__,
];
foreach ($filesToRemove as $file) {
if (file_exists($file)) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
removeDirectory($file);
}
}
}
file_put_contents('README.md', '');
function removeDirectory(string $dir): bool
{
if (! is_dir($dir)) {
return false;
}
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$file);
if ($path === false) {
continue;
}
if (is_dir($path)) {
removeDirectory($path);
} else {
unlink($path);
}
}
return rmdir($dir);
}