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
|
<?php
class p_cp extends prog {
/* This method (recurse_copy) was written by gimmicklessgpt@gmail.com
* and posted to the PHP manual comments section on 20-May-2009 11:04
*/
static function recurse_copy($src,$dst) {
//echo 'recurse_copy('.$src.', '.$dst.");\n";
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
self::recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
self::copy( $src.'/'.$file , $dst.'/'.$file );
}
}
}
closedir($dir);
}
static function copy($src,$dst) {
//echo 'copy('.$src.', '.$dst.");\n";
copy($src, $dst);
}
public static function main($args, $env) {
$me = array_shift($args);
$flags = '';
while (substr($args[0],0,1) == '-') {
$flags .= array_shift($args);
}
$flags = preg_replace('/[ -]/','',$flags);
if (strpos($flags,'r')===false) { self::copy($args[0],$args[1]); }
else { self::recurse_copy($args[0],$args[1]); }
}
}
|