+ Reply to Thread
Results 1 to 4 of 4

Thread: Deleting A directory

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Deleting A directory

    I have been working on a software package. All the install files are in a folder called install. When the installation is finished they are forwarded to a file called delete_install.php which is in the install folder. I have been trying to figure out how to delete the install folder and all files in it. I found the code below but im unsure if it will work properly.

    Code:
    <?php
    $dirname = './install';
    
    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;
    
    ?>
    Will this work or do I need to do something else. Thanks in advance.

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Deleting A directory

    This looks like it will work correctly, but I am unsure if you are able to delete the script being executed. You will probably have to have the file outside of the install directory, or create a temporary uninstall file from the script. Also the 'return true' is only used like that for included files, or functions. As it is I believe you would receive an error.

    Run it and tell us what happens
    Last edited by Twinkie; 06-30-2009 at 05:59 PM.

  3. #3
    nirajkum is offline x10 Sophmore nirajkum is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    161

    Re: Deleting A directory

    the code seems to be okie ... u need not to worry about that please make sure you delete install.php properly

  4. #4
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Deleting A directory

    The first line, $dirname, is a wrong value. How you presented it, the $dirname points to the /install/install directory.
    Put two dots instead of one, this should change the directory.
    Last edited by xav0989; 07-03-2009 at 02:04 AM.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. Disk Full
    By digitaljit in forum Free Hosting
    Replies: 2
    Last Post: 11-10-2008, 06:07 AM
  2. 550 Can't remove directory: Directory not empty
    By 9svn6 in forum Free Hosting
    Replies: 3
    Last Post: 10-02-2008, 12:37 PM
  3. samba server issue
    By hopper in forum Computers & Technology
    Replies: 2
    Last Post: 04-13-2008, 10:59 PM
  4. Introduction to Linux CLI
    By HomerJ in forum Tutorials
    Replies: 3
    Last Post: 02-26-2008, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers