Web Analytics Made Easy -
StatCounter unlink()? - CodingForum

Announcement

Collapse
No announcement yet.

unlink()?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • unlink()?

    How do you delete a directory?

    I have always used unlink() to delete files, and just the other day tried to delete a directory with it. This is what I put:

    unlink("./folder/");

    Is there a reason that doesnt work? Do I need an extra parameter if it is for a directory?

    Thanks in advance!
    Jared Brandt
    IKinsler

  • #2
    Try rmdir

    More info : http://www.php.net/manual/en/function.rmdir.php
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

    Comment


    • #3
      Are you sure the dir dosn't have any files in it? If so it won't work : you need to delete them first.
      I don't suffer from insanity, I enjoy every single minute of it!

      Comment


      • #4
        OH! Well that's my problem then! I've still got files! I will try deleting them and THEN rmdir().

        Thanks to both of you!
        Jared Brandt
        IKinsler

        Comment


        • #5
          Here's a function somebody came up with a while ago that will clean the files in the dir and them remove the dir...

          PHP Code:
          <?php
          function delete($file) {
           
          chmod($file,0777);
           if (
          is_dir($file)) {
            
          $handle opendir($file); 
            while(
          $filename readdir($handle)) {
             if (
          $filename != "." && $filename != "..")
          {
              
          delete($file."/".$filename);
             }
            }
            
          closedir($handle);
            
          rmdir($file);
           } else {
            
          unlink($file);
           }
          }
          delete("ordnername");
          ?>
          Moderator, Perl/CGI Forum
          shadowstorm.net - subvert society

          Comment


          • #6
            Thanks, Feyd!

            I had that figured out, but unfortunately that doesn't work either! You see, I have no idea how many directories are in the directory I wish to delete - it could be 10 or 20! I had a function that would delete it if it was a file, and empty it and then delete it if it was a dir. But, apparently you cannot launch a function if you're already in it! So that didn't work either.
            Jared Brandt
            IKinsler

            Comment


            • #7
              How about having two functions :

              One that does the cleaning
              One that calls the one that does the cleaning.

              The the first function goes upon another dir it calls the second function which calls the first.....

              Should work.....
              I don't suffer from insanity, I enjoy every single minute of it!

              Comment


              • #8
                not for the feint-hearted...

                exec('rm -f -R /get/this/path/right/directory');

                but be sure to get the path right else tears will be forthcoming & dont blame me.
                note some hosts disallow exec() calls.
                resistance is...

                MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

                Comment

                Working...
                X