2

I want copy all the files of a folder to another folder. So how to copy recursively in wordpress.

3
  • 1
    What files? From where to where?
    – kaiser
    Sep 25, 2014 at 9:40
  • I want to copy all the files from one of my plugin inside plugins directory to the active theme directory. Sep 25, 2014 at 9:50
  • 1
    Please: As (usual as) edit. Also, please read How to Ask.
    – kaiser
    Sep 25, 2014 at 10:08

1 Answer 1

5

You can make use of the Filesystem API, especially the copy_dir() function - source - does seem to be what you are looking for. Take a look at the docblock from the above source link for a little bit more information:

/**
* Copies a directory from one location to another via the WordPress Filesystem Abstraction.
* Assumes that WP_Filesystem() has already been called and setup.
*
* @since 2.5.0
*
* @param string $from source directory
* @param string $to destination directory
* @param array $skip_list a list of files/folders to skip copying
* @return mixed WP_Error on failure, True on success.
*/

The (very) basic usage scenario would look like this:

global $wp_filesystem;
copy_dir( 
    '/path/you/are/copying/from/', 
    '/path/you/are/copying/to/'
);

Unfortunately the Filesystem API isn't exactly well documented. You definitely should take a look at the linked codex article. One additional (almost always) linked source of information would be the article by @Otto:

Besides that there are some Q&A's on here which might be helpful:

Note, the above are just a small sample, use the search to find more. Last but not least, to take a closer look at the source to learn and know more about it should definitely be on your agenda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.