Jump to content

search and delete a file in a subdirectory...?


acctman

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.