echo | PHP | 2011 年 12 月 7 日
php文件拷贝脚本

最近在进行大量的文件对比工作,其中需要进行文件的提取,知道了文件列表后,一个一个复制起来很麻烦,写了个脚本,代码如下:

<?php


 //list3 文件列表可直接提供,从本地获取。
 //删除list1,需要手工执行unlink操作。

$arr = array(
	'list3' =>
        array(
		'admin\cloud\cloud_connect.php',
		'admin\cloud\cloud_doctor.php',
		'admin\cloud\cloud_manyou.php',
		'admin\cloud\cloud_search.php',
		'admin\cloud\cloud_siteinfo.php',
		'admin\cloud\cloud_stats.php',
		'admin\cloud\cloud_union.php',
		'admin\menu\menu_cloud.php',
		'admin\cloud.inc.php',
		'api\manyou\class\APIErrorResponse.php',
		'api\manyou\class\APIResponse.php',
		'api\manyou\class\Application.php',
		'api\manyou\class\Cloud.php',
		'api\manyou\class\CloudClient.php',
		'api\manyou\class\Common.php',
		'api\manyou\class\Connect.php',
		'api\manyou\class\Credit.php',
		'api\manyou\class\Feed.php',
		'api\manyou\class\Friends.php',
		'api\manyou\class\MiniBlog.php',
		'api\manyou\class\MyBase.php',
		'api\manyou\class\NewsFeed.php',
		'api\manyou\class\Notifications.php',
		'api\manyou\class\Photo.php',
		'api\manyou\class\Profile.php',
		'api\manyou\class\Request.php',
		'api\manyou\class\Search.php',
		'api\manyou\class\Site.php',
		'api\manyou\class\Union.php',
		'api\manyou\class\UserApplication.php',
		'api\manyou\class\Users.php',
		'api\manyou\channel.htm',
		'api\manyou\cloud_channel.htm',
		'api\manyou\cloud_iframe.js',
		'api\manyou\index.htm',
		'api\manyou\my.php',
		'api\my.php',
		'connect\connect_config.php',
		'connect\connect_feed.php',
		'connect\connect_logging.php',
		'connect\connect_login.php',
		'connect\connect_register.php',
		'connect\connect_share.php',
		'connect\connect_user.php',
		'images\admincp\cloud\btn.png',
		'images\admincp\cloud\btn_push.png',
		'images\admincp\cloud\cloud.css',
		'images\admincp\cloud\cloud.js',
		'images\admincp\cloud\editor_bg.png',
		'images\admincp\cloud\editor_btn.png',
		'images\admincp\cloud\fwin_menu.jpg',
		'images\admincp\cloud\ico_d.png',
		'images\admincp\cloud\image_s.gif',
		'images\admincp\cloud\jquery.min.js',
		'images\admincp\cloud\line.png',
		'images\admincp\cloud\message.png',
		'images\admincp\cloud\pn.png',
		'images\admincp\cloud\pt.png',
		'images\admincp\cloud\qqgroup.css',
		'images\admincp\cloud\qqgroup.js',
		'images\admincp\cloud\qun_bg.png',
		'images\admincp\cloud\qun_btn.png',
		'images\admincp\cloud\qun_op.png',
		'images\admincp\cloud\qun_op_list.png',
		'images\admincp\cloud\qun_op_top.png',
		'images\admincp\cloud\right.gif',
		'images\admincp\cloud\thumb.png',
		'images\admincp\cloud\wrong.gif',
		'images\default\connect_config_mark.png',
		'images\default\connect_qq.gif',
		'images\default\pengyou.png',
		'images\default\qq_bind.gif',
		'images\default\qq_bind_small.gif',
		'images\default\qq_login.gif',
		'images\default\qzone.gif',
		'images\default\weibo.png',
		'include\tasks\connect_bind.cfg.php',
		'include\tasks\connect_bind.inc.php',
		'include\cloud.func.php',
		'include\cloud_plugin.func.php',
		'include\connect.func.php',
		'plugins\cloudstats\cloudstats.class.php',
		'plugins\cloudstats\discuz_plugin_cloudstats.xml',
		'plugins\cloudstats\setting.inc.php',
		'plugins\qqconnect\templates\extend_common.css',
		'plugins\qqconnect\templates\extend_module.css',
		'plugins\qqconnect\templates\index.htm',
		'plugins\qqconnect\templates\login.htm',
		'plugins\qqconnect\templates\module.htm',
		'plugins\qqconnect\templates\register.htm',
		'plugins\qqconnect\templates\share.htm',
		'plugins\qqconnect\templates\spacecp.htm',
		'plugins\qqconnect\admin.inc.php',
		'plugins\qqconnect\connect.class.php',
		'plugins\qqconnect\discuz_plugin_qqconnect.xml',
		'plugins\qqconnect\index.htm',
		'plugins\qqconnect\install.php',
		'plugins\qqconnect\logo.inc.php',
		'plugins\qqconnect\spacecp.inc.php',
		'plugins\search\misc\api_form_bg_center.gif',
		'plugins\search\misc\api_form_bg_left.gif',
		'plugins\search\misc\api_form_bg_right.gif',
		'plugins\search\misc\api_form_search.gif',
		'plugins\search\misc\api_form_submit.gif',
		'plugins\search\misc\api_form_submit_forum.gif',
		'plugins\search\misc\form.css',
		'plugins\search\common.php',
		'plugins\search\discuz_plugin_search.xml',
		'plugins\search\form.inc.php',
		'plugins\search\index.html',
		'plugins\search\index.inc.php',
		'plugins\search\install.php',
		'plugins\search\plugin.class.php',
		'plugins\search\register.func.php',
		'plugins\search\register.php',
		'plugins\search\uninstall.php',
		'templates\default\admincp.cloud.lang.php',
		'templates\default\my_search_form.htm',
		'connect.php',
		'my_search.php',
	),
	'list4' =>
        array(
		'admin\main.inc.php',
		'admin\members.inc.php',
		'admin\menu.inc.php',
		'include\cache.func.php',
		'include\newthread.inc.php',
		'include\newtrade.inc.php',
		'manyou\api\my.php',
		'plugins\manyou\discuz_plugin_manyou.xml',
		'plugins\manyou\index.htm',
		'plugins\manyou\install.php',
		'plugins\manyou\plugin.class.php',
		'plugins\manyou\uninstall.php',
		'templates\default\forumdisplay.htm',
		'templates\default\header.htm',
		'templates\default\index_header.htm',
		'templates\default\login.htm',
		'templates\default\manyou_admincp.htm',
		'templates\default\manyou_appnav.htm',
		'templates\default\post.htm',
		'templates\default\post_infloat.htm',
		'templates\default\register.htm',
		'templates\default\tasks.lang.php',
		'templates\default\templates.lang.php',
		'templates\default\viewthread_node.htm',
		'admincp.php',
		'post.php',
		'search.php',
		'viewthread.php',
	),
);
foreach ($arr as $li => $di ) {
	if ($li == 'list1') {
	    mkdir('./list1');
		copy_files($di,$li);
		echo '<br /><br />';
	}elseif ($li == 'list2') {
	    mkdir('./list2');
		copy_files($di,$li);
		echo '<br />';
	}elseif ($li == 'list3') {
	    mkdir('./list3');
		copy_files($di,$li);
		echo '<br />';
	}elseif ($li == 'list4') {
	    mkdir('./list4');
		copy_files($di,$li);
		echo '<br />';
	}
}

/**
 * @param      $files
 * @param      $li
*/
function copy_files($files,$li){
	$n = $b = '';
	foreach ($files as $value) {
		if (is_file('./'.$value)) {
			$dirc = explode('\\', $value);//以反斜杠为切割字符串标记
			foreach ($dirc as $v) {
				if (is_dir('./'.$b.$v)) {	//是目录就创建目录
					$r = mkdir('./'.$li.'/'.$b.$v);
					$b = $b.$v.'/';
				}elseif(is_file('./'.$b.$v)) {	//是文件则copy文件到创建的目录下
					$b = $b.$v;
					if (!copy ('./'.$b, $li."/".$b)){
						echo $b."<br />";
					}else{
						echo './'.$b.' <b>has been copied.</b>'.'<br />';
						$n++;//各个list文件总数
					}
				}
			}
			unset($b);
		}
	}
	echo $li.' <b>'.$n.'</b> files has been copied.';
}
// end
?>
list3、4就是预先知道,且要提取的的文件列表。如果有兴趣或者对你来说有用,可以自己修改完善。
本文地址:https://www.uut8.com/php/138.html
« »

没有评论

发表评论