2

My function cleanup looks like that.

function cleanUp($exdirs, $exfiles){
$it = new RecursiveIteratorIterator(
  new RecursiveDirectoryIterator('.'), 
  RecursiveIteratorIterator::CHILD_FIRST
);
foreach($it as $entry) {
  if ($entry->isDir() && !in_array($entry->getBasename(), $exdirs)) {
    try {
      rmdir($entry->getPathname());
    }
    catch (Exception $ex) {
      // dir not empty
    }
  }
  elseif (!in_array($entry->getFileName(), $exfiles)) {
    unlink($entry->getPathname());
  }
}
}

And calling this function like that

$excludeDirsNames = array('cgi-bin');
$excludeFileNames = array('ws.zip');
cleanUp($excludeDirsNames , $excludeFileNames);

Now the problem is i'm getting warning message. can not unlink cgi-bin on line unlink($entry->getPathname());

What's wrong with my function? How to fix that problem?

4
  • Have you checked permissions on that directory? Commented Oct 8, 2011 at 8:20
  • which one? cgi-bin is exclusion. I'm sending exclusions array to function Commented Oct 8, 2011 at 8:21
  • please read your warning message once again: can not unlink cgi-bin on line. It is clear for me that you're trying to delete cgi-bin directory and you have no enough permissions for it. Commented Oct 8, 2011 at 8:25
  • it is not necessary to read the function, the warning message states clearly that you're trying to delete it. And you can disclaim this, but php doesn't lie. Commented Oct 8, 2011 at 8:51

1 Answer 1

2

I am guessing that cgi-bin is a symlink and not a regular directory. That's why it's getting into the "unlink" section. The error message is probably due to permissions.

The fix, move 'cgi-bin' to the $excludeFileNames array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.