Results 1 to 4 of 4

Thread: How to make PHP remove a Directory

  1. #1
    Join Date
    May 2009
    Posts
    1,952

    How to make PHP remove a Directory

    That is all i wanted to know. I need a script that will make PHP delete a specified folder or a directory.

    Please help me soon. I need it in urgent. Thanks in advance

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to make PHP remove a Directory

    Its very small and simple. here it is :-

    function rmdir_r ( $dir, $DeleteMe = TRUE )
    {
    if ( ! $dh = @opendir ( $dir ) ) return;
    while ( false !== ( $obj = readdir ( $dh ) ) )
    {
    if ( $obj == '.' || $obj == '..') continue;
    if ( ! @unlink ( $dir . '/' . $obj ) ) rmdir_r ( $dir . '/' . $obj, true );
    }

    closedir ( $dh );
    if ( $DeleteMe )
    {
    @rmdir ( $dir );
    }
    }

  3. #3
    Join Date
    Feb 2009
    Posts
    391

    Re: How to make PHP remove a Directory

    It’s a recursive function that deletes the directory with its files, folders and sub-folders.


    function delete_directory($dirname) {
    if (is_dir($dirname))
    $dir_handle = opendir($dirname);
    if (!$dir_handle)
    return false;
    while($file = readdir($dir_handle)) {
    if ($file != "." && $file != "..") {
    if (!is_dir($dirname."/".$file))
    unlink($dirname."/".$file);
    else
    delete_directory($dirname.'/'.$file);
    }
    }
    closedir($dir_handle);
    rmdir($dirname);
    return true;
    }

  4. #4
    Join Date
    May 2009
    Posts
    1,952

    Re: How to make PHP remove a Directory

    Thanks buddy. I really needed that urgently. I tried this and it works perfectly for.

    I appreciate your help.

Similar Threads

  1. Google chrome cannot make directory for unzipping
    By LavinaD in forum Technology & Internet
    Replies: 6
    Last Post: 27-08-2011, 10:41 PM
  2. How to remove a directory in C#
    By MACE in forum Software Development
    Replies: 3
    Last Post: 13-11-2009, 05:18 PM
  3. How To remove directory in linux
    By Vespera in forum Operating Systems
    Replies: 3
    Last Post: 16-05-2009, 02:41 PM
  4. How to make use of VB Script to get Current Directory?
    By BenTen in forum Software Development
    Replies: 2
    Last Post: 12-01-2009, 08:34 PM
  5. Replies: 1
    Last Post: 07-02-2008, 10:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,259,050.18050 seconds with 16 queries