How PHP replicates some directories under a folder

Source: Internet
Author: User
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);}}




This PHP code is in my program, a copy of the directory under the Thousand folder into another folder, there are many directories, such as the folder contains 1-100 directory names are 1-100, I just want to copy: 1,2,3,4 These directories other do not copy, this PHP need to change a bit, I am a novice, hope to get expert guidance!


Reply to discussion (solution)

if (Is_dir ("$path/$file")) {
Switch

if (Is_dir ("$path/$file") && In_array ($file, Array (' 1 ', ' 2 ', ' 3 ', ' 4 '))) {

Again, if you do not want to copy the root directory, test.txt files only copy the 1,2,3,4 directory, how should you change it??

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.