Jump to content

Recommended Posts

i'm using the following two functions to delete all directories and to delete a single file. Can someone assist me with a function that will search all subdirectories for a specific file then delete it?

 

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

function usr_del_file($usrfile) {
if(is_file($usrfile)) {
@unlink($usrfile);
}
}

will, not exactly.. but you'd need not JUST a LOOP, you'd need a recursive function which loops a single directory and everytime it encounters another directory, begin that loop on the other directories.. its a lil advanced but you could get it right if you try hard enough

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.