SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete but not first directory

    Hello,

    i'm using this function to delete all content in some_directory IN "upload" directory:

    PHP Code:
    function remove_directory($directory$empty=FALSE)
     {
     
       if(
    substr($directory,-1) == '/')
        {
            
    $directory substr($directory,0,-1);
        }
        if(!
    file_exists($directory) || !is_dir($directory))
       {
             return 
    FALSE;
       }elseif(
    is_readable($directory))
        {
             
    $handle opendir($directory);
             while (
    FALSE !== ($item readdir($handle)))
             {
                 if(
    $item != '.' && $item != '..')
                 {
                     
    $path $directory.'/'.$item;
                     if(
    is_dir($path)) 
                     {
                     
                         
    remove_directory($path);
                     }else{
                        
    unlink($path);
                     }
                 }
             }
             
    closedir($handle);
             if(
    $empty == FALSE)
             {
                 if(!
    rmdir($directory))
                 {
                     return 
    FALSE;
                 }
             }
         }     return 
    TRUE;
     } 
    PHP Code:
    remove_directory("./upload/" $dirname); 
    But, PROBLEM is that it deletes "UPLOAD" directory too How can i delete all in "UPLOAD_here_4_ever/folder_2_delete/all_here_delete/..."

    I guess you understand me... I don't need to delete "UPLOAD" directory!!

  2. #2
    Codehead. hamidof's Avatar
    Join Date
    Dec 2005
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Call this function like this:
    PHP Code:
           remove_directory("./upload/" $dirnametrue); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hamidof View Post
    Call this function like this:
    PHP Code:
           remove_directory("./upload/" $dirnametrue); 
    I have tryed but it doesnt delete anything

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there anyone who could help me?

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you not telling it to remove 'upload'

    PHP Code:
    remove_directory("./upload/" $dirname); 
    Surely if you want to keep this and delete a sub directory of 'upload' you need to specify that subdirectory

    PHP Code:
    remove_directory("./upload/deletethis" $dirname); 
    Just a thought


    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    Are you not telling it to remove 'upload'

    PHP Code:
    remove_directory("./upload/" $dirname); 
    Surely if you want to keep this and delete a sub directory of 'upload' you need to specify that subdirectory

    PHP Code:
    remove_directory("./upload/deletethis" $dirname); 
    Just a thought
    I have specified:

    PHP Code:
    remove_directory("./upload/" $dirnametrue); 
    It needs to delete $dirname, but it deletes always "upload" directory

  7. #7
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry my bad, I must wear my glasses more I saw your . as a ,
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  8. #8
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you sure that $dirname contains a value?

    If it doesnt then the path to delete will be "./upload/"

    echo out the value of the $dirname just prior to calling remove_directory
    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cronsrcs View Post
    are you sure that $dirname contains a value?

    If it doesnt then the path to delete will be "./upload/"

    echo out the value of the $dirname just prior to calling remove_directory
    it's working now Thank you so much!! I'm so stupid, i didn't check I/O vars...


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
  •