Jump to content

Recommended Posts

Hi all

 

I use this code to delete a directory (called with: full_rmdir("../dir"); )

 

<?php
function full_rmdir($dirname){
        if ($dirHandle = opendir($dirname)){
            $old_cwd = getcwd();
            chdir($dirname);

            while ($file = readdir($dirHandle)){
                if ($file == '.' || $file == '..') continue;

                if (is_dir($file)){
                    if (!full_rmdir($file))
                     echo "Error";
                     return false;
                }else{
                    if (!unlink($file)) 
                    echo "Error";
                    return false;
                }
            }

            closedir($dirHandle);
            chdir($old_cwd);
            if (!rmdir($dirname)) 
            echo "Error";
            return false;

            echo "Directory deleted";
            return true;
        }else{
            echo "Error";
            return false;
        }
    }
?>

 

With this code above,

-if I delete a directory it's ok;

-if I delete more directories (with a for structure) I have more messages "Directory deleted";

-if I delete some directories (some deleted and some yet to delete) I have more error messages and more good messages.

 

Ho can I do have the right messages?

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/56529-delete-a-directory/
Share on other sites

the problem is that I would to print

 

1 message of folder/s deleted

OR

1 message of folder/s not deleted.

 

The code above, print (with echo)

1 message if the folder/s is deleted (it's ok)

1 message if the folder/s is not deleted (it's ok)

1 or more messages if I delete more than one folder

1 or more messages if I delete folder/s already deleted and some yet to delete.

 

 

Link to comment
https://forums.phpfreaks.com/topic/56529-delete-a-directory/#findComment-279198
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.