-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove-wrong-datapack-file.php
61 lines (61 loc) · 2.09 KB
/
remove-wrong-datapack-file.php
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
50
51
52
53
54
55
56
57
58
59
60
61
<?php
function rmPath($folder)
{
if(preg_match('#/diff/?$#isU',$folder) || preg_match('#^diff/?$#isU',$folder) || preg_match('#/pack/?$#isU',$folder) || preg_match('#^pack/?$#isU',$folder))
return array();
if(!preg_match('#/$#',$folder))
$folder.='/';
$arr=array();
if(is_dir($folder))
if($handle = opendir($folder))
{
while(false !== ($entry = readdir($handle)))
{
if($entry != '.' && $entry != '..')
{
if(is_file($folder.$entry))
unlink($folder.$entry);
else if(is_dir($folder.$entry))
rmPath($folder.$entry.'/');
}
}
closedir($handle);
rmdir($folder);
}
}
function listFolder($folder)
{
if(preg_match('#/diff/?$#isU',$folder) || preg_match('#^diff/?$#isU',$folder) || preg_match('#/pack/?$#isU',$folder) || preg_match('#^pack/?$#isU',$folder))
return array();
if(!preg_match('#/$#',$folder))
$folder.='/';
$arr=array();
if($handle = opendir($folder)) {
while(false !== ($entry = readdir($handle)))
{
if($entry != '.' && $entry != '..')
{
if(preg_match('#^[0-9/a-z\\.\\- _]+$#',$folder))
{
if(is_file($folder.$entry))
{
if(preg_match('#\\.(tmx|xml|tsx|js|png|jpg|gif|ogg|qml|qm|ts|txt)$#',$entry))
{
if(!preg_match('#^[0-9/a-z\\.\\- _]*[0-9a-z]\\.[a-z]{2,4}$#',$folder.$entry))
unlink($folder.$entry);
}
else
unlink($folder.$entry);
}
else if(is_dir($folder.$entry))
$arr=array_merge($arr,listFolder($folder.$entry.'/'));
}
else
rmPath($folder);
}
}
closedir($handle);
}
return $arr;
}
$arr=listFolder('./');