Remove an empty directory in php

An empty existing directory can be removed by using the rmdir() php function.

Example use of rmdir():

<?php 
if (file_exists("/temp/test")) {
  rmdir("/temp/test");
  print("Directory removed.\n");
} else {
  print("Directory does not exist.\n");
}
?>

This script will print:

Directory removed.

If you run this script again, it will print:

Directory does not exist.

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: PHP File Handling

Tags:

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.