forked from liexusong/php-beast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode_files.php
62 lines (48 loc) · 1.33 KB
/
encode_files.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
/**
* Encode files by directory
* @author: Howard.Lee
*/
function encode_files($dir, $new_dir)
{
$dir = rtrim($dir, '/');
$new_dir = rtrim($new_dir, '/');
$handle = opendir($dir);
if (!$handle) {
return false;
}
while (($file = readdir($handle))) {
if ($file == '.' || $file == '..') {
continue;
}
$path = $dir . '/' . $file;
$new_path = $new_dir . '/' . $file;
if (is_dir($path)) {
if (!is_dir($new_path)) {
mkdir($new_path, 0777);
}
encode_files($path, $new_path);
} else {
$infos = explode('.', $file);
if (strtolower($infos[count($infos)-1]) == 'php') {
if (!beast_encode_file($path, $new_path)) {
echo "Failed to encode file `{$path}'\n";
}
} else {
copy($path, $new_path);
}
}
}
}
if (count($argv) < 3) {
exit("Usage: encode_files.php <old_path> <new_path>\n\n");
}
$old_path = $argv[1];
$new_path = $argv[2];
if (!is_dir($old_path)) {
exit("Fatal: path `{$old_path}' not exists\n\n");
}
if (!is_dir($new_path) && !mkdir($new_path, 0777)) {
exit("Fatal: can not create directory `{$newpath}'\n\n");
}
encode_files($old_path, $new_path);