private function appendFiles(Writer $writer, $files, PhingFile $dir = null)
    {
        if (!empty($files)) {
            $this->log(
                "Attempting to append " . count(
                    $files
                ) . " files" . ($dir !== null ? ", using basedir " . $dir->getPath() : "")
            );
            $basenameSlot = Register::getSlot("task.append.current_file");
            $pathSlot = Register::getSlot("task.append.current_file.path");
            foreach ($files as $file) {
                try {
                    if (!$this->checkFilename($file, $dir)) {
                        continue;
                    }

                    if ($dir !== null) {
                        $file = is_string($file) ? new PhingFile($dir->getPath(), $file) : $file;
                    } else {
                        $file = is_string($file) ? new PhingFile($file) : $file;
                    }
                    $basenameSlot->setValue($file);
                    $pathSlot->setValue($file->getPath());
                    $this->appendFile($writer, $file);
                } catch (IOException $ioe) {
                    $this->log(
                        "Unable to append contents of file " . $file . ": " . $ioe->getMessage(),
                        Project::MSG_WARN
                    );
                } catch (NullPointerException $npe) {
                    $this->log(
                        "Unable to append contents of file " . $file . ": " . $npe->getMessage(),
                        Project::MSG_WARN
                    );
                }
            }
        }
    }