Title: mkdir function not working
Last modified: August 20, 2016

---

# mkdir function not working

 *  Resolved [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/)
 * This works fine when testing it on a page with a custom template:
 * add_action (‘folder’, function(){
    $tempDir = realpath(‘wp-content/themes’); 
   $tempDir = $tempDir.”\used-car-lot-theme”; mkdir($tempDir,0700);}
 * but when I move it to the register_activation_hook function in my plugin it pukes
   with this error:
    Warning: mkdir() [function.mkdir]: File exists and the folder
   is not created. (and no, the file does not exist).
 * Help please 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Chris](https://wordpress.org/support/users/zenation/)
 * (@zenation)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/#post-3248522)
 * Have you checked what $tempDir (e.g. with var_dump) “really” contains when calling
   it via the register activation hook?
    Maybe using ABSPATH instead of realpath()
   does a better job?
 *     ```
       $tempDir = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'used-car-lot-theme';
       ```
   
 *  Thread Starter [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/#post-3248552)
 * Yes, actually I did check it.
    My version produces: C:\xampp\htdocs\wordpress\
   wp-content\themes\used-car-lot-theme
 * Your version produces:
    C:\xampp\htdocs\wordpress/\wp-content\themes\used-car-
   lot-theme
 *  so,
    I removed the first DIRECTORY_SEPARATOR from your line and got: C:\xampp\
   htdocs\wordpress/wp-content\themes\used-car-lot-theme
 * And it worked!
    Apparently, the path TO and FROM the working directory needs 
   to be there to create the directory.
 * Now all I need to do is handle the “File Exists” notice.
    while I’m working on
   it ……… Any suggestions are welcome.
 * Thank You Chris.
 *  Thread Starter [yeagerc50](https://wordpress.org/support/users/yeagerc50/)
 * (@yeagerc50)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/#post-3248553)
 * The @ symbol suppresses the notice. [@mkdir](https://wordpress.org/support/users/mkdir/)()
 *  [Chris](https://wordpress.org/support/users/zenation/)
 * (@zenation)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/#post-3248556)
 * Right. And you could still handle errors based on error_get_last()
 *     ```
       if( !file_exists( $tempDir ) && !@mkdir( $tempDir ) ) {
         $error = error_get_last();
         ...
       }
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘mkdir function not working’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [Chris](https://wordpress.org/support/users/zenation/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/mkdir-function-not-working/#post-3248556)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
