3

I have successfully used copy_dir() to copy a directory to a new location. How can I delete a directory using WordPress functions?

1
  • WP_Filesystem(); copy_dir(source,des); worked! , how to delete?
    – Ali Dbg
    Commented Aug 30, 2014 at 14:28

1 Answer 1

5

The method rmdir() - source - :

/**
 * Delete a directory.
 *
 * @since 2.5.0
 *
 * @param string $path Path to directory.
 * @param bool $recursive Optional. Whether to recursively remove files/directories.
 * Default false.
 * @return bool Whether directory is deleted successfully or not.
 */
public function rmdir( $path, $recursive = false ) {
    return false;
}

from the WP_Filesystem_Base class should work for that purpose.

The method rmdir() is part of the classes that extend WP_Filesystem_Base, like WP_Filesystem_Direct and accordingly there is the rmdir() method in that class. Take a look at the the wp-admin/includes directory to inspect the other classes yourself.

So just copy the directory with copy_dir() - source - and then remove it with above method.

A bit more general information about the Filesystem API can be found at the codex page.

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.