Heim  >  Artikel  >  Backend-Entwicklung  >  PHP如何复制文件夹下的某些目录

PHP如何复制文件夹下的某些目录

WBOY
WBOYOriginal
2016-06-23 14:17:291234Durchsuche

PHP

function copy_module_file($path,$newp){	if(!is_dir($newp)){		mkdir($newp);	}	if (file_exists($path)){		if(is_file($path)){			copy($path,$newp);		} else{			$handle = opendir($path);			while (($file = readdir($handle))!='') {				if (($file!=".") && ($file!="..") && ($file!="")){					if (is_dir("$path/$file")){						copy_module_file("$path/$file","$newp/$file");					} else{						copy("$path/$file","$newp/$file");					}				}			}			closedir($handle);		}	}}




这段php代码是我程序中的,一个复制些个文件夹下的目录到另一个文件夹下,里面有好多目录,比如该文件夹里面有1-100个目录名字分别是1-100,我只想复制: 1,2,3,4 这几目录其它的不复制,这段php需要怎么改一下,我是新手,希望得到高手指点! 

回复讨论(解决方案)

if (is_dir("$path/$file")){
改为:

if (is_dir("$path/$file") && in_array($file,array('1','2','3','4'))){

再问一下,如果不想复制根目录里的,test.txt文件只复制1,2,3,4目录,应该怎么再改一下,??

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:SVN目录规划问题Nächster Artikel:mysql 蠕虫复制出错