Home > Backend Development > PHP Tutorial > PHP如何复制文件夹下的某些目录

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

WBOY
Release: 2016-06-23 14:17:29
Original
1315 people have browsed it

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);		}	}}
Copy after login




这段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'))){
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template