Example #1
0
/**
 * Recursive get files
 *
 * @param string Base directory to search in
 * @param string Search pattern
 */
function RecursiveGlob($inPath = '', $inPattern = '*')
{
    $res = array();
    // Check path
    if (!is_dir($inPath)) {
        return $res;
    }
    // Get the list of directories
    if (substr($inPath, -1) != DIRECTORY_SEPARATOR) {
        $inPath .= DIRECTORY_SEPARATOR;
    }
    // Add files from the current directory
    $files = glob($inPath . $inPattern, GLOB_MARK | GLOB_NOSORT);
    foreach ($files as $item) {
        if (substr($item, -1) == DIRECTORY_SEPARATOR) {
            continue;
        }
        $res[] = $item;
    }
    // Scan sub directories
    $paths = glob($inPath . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
    foreach ($paths as $path) {
        $res = array_merge($res, RecursiveGlob($path, $inPattern));
    }
    return $res;
}
Example #2
0
<?php

/**
 * Epub loader application action: load ebooks into calibre databases
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Didier Corbière <*****@*****.**>
 */
// Init database file
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . 'metadata.db';
try {
    // Open or create the database
    $db = new CalibreDbLoader($fileName, $gConfig['create_db']);
    echo sprintf('Load database %s', $fileName) . '<br />';
    // Add the epub files into the database
    if (!empty($dbConfig['epub_path'])) {
        $fileList = RecursiveGlob($dbConfig['epub_path'], '*.epub');
        foreach ($fileList as $file) {
            $error = $db->AddEpub($file);
            if (!empty($error)) {
                $gErrorArray[$file] = $error;
            }
        }
    }
} catch (Exception $e) {
    $gErrorArray[$fileName] = $e->getMessage();
}