Jump to content

Remove directories not empty


christa

Recommended Posts

hi,

i have an array that contains some names (1,4,6,56...). Every integer is a name of a folder.

 

I must to delete only the folders in array, i use this code:

 

$all_folders = array();
while ($row = mysql_fetch_array($result)) {
    $all_folders[] = $row['folder_id'];
}

function removedirfiles($all_folders){
  $open=readdir($all_folders);
  while($files=readdir($open)){
    unlink("$all_folders/$files");
  }
rmdir($all_folders);
}

removedirfiles("$all_folders");

 

but it returns those errors:

 

readdir(): supplied argument is not a valid Directory resource

rmdir(Array) [function.rmdir]: No such file or directory

Link to comment
https://forums.phpfreaks.com/topic/182643-remove-directories-not-empty/
Share on other sites

hi,

i have an array that contains some names (1,4,6,56...). Every integer is a name of a folder.

 

I must to delete only the folders not in array, i use this code:

 

$all_folders = array();
while ($row = mysql_fetch_array($result)) {
    $all_folders[] = $row['folder_id'];
}

function removedirfiles($all_folders){
  $open=readdir($all_folders);
  while($files=readdir($open)){
    unlink("$all_folders/$files");
  }
rmdir($all_folders);
}

removedirfiles("$all_folders");

 

but it returns those errors:

 

readdir(): supplied argument is not a valid Directory resource

rmdir(Array) [function.rmdir]: No such file or directory

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.