当前位置: 首页>>代码示例>>PHP>>正文


PHP scandir函数代码示例

本文整理汇总了PHP中scandir函数的典型用法代码示例。如果您正苦于以下问题:PHP scandir函数的具体用法?PHP scandir怎么用?PHP scandir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了scandir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     if (!file_exists($path)) {
         $output->writeln("{$path} is not a file or a path");
     }
     $filePaths = [];
     if (is_file($path)) {
         $filePaths = [realpath($path)];
     } elseif (is_dir($path)) {
         $filePaths = array_diff(scandir($path), array('..', '.'));
     } else {
         $output->writeln("{$path} is not known.");
     }
     $generator = new StopwordGenerator($filePaths);
     if ($input->getArgument('type') === 'json') {
         echo json_encode($this->toArray($generator->getStopwords()), JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
         echo json_last_error_msg();
         die;
         $output->write(json_encode($this->toArray($generator->getStopwords())));
     } else {
         $stopwords = $generator->getStopwords();
         $stdout = fopen('php://stdout', 'w');
         echo 'token,freq' . PHP_EOL;
         foreach ($stopwords as $token => $freq) {
             fputcsv($stdout, [utf8_encode($token), $freq]) . PHP_EOL;
         }
         fclose($stdout);
     }
 }
开发者ID:yooper,项目名称:php-text-analysis,代码行数:30,代码来源:StopWordsCommand.php

示例2: fileTree

 /**
  * 
  * @return string
  */
 public static function fileTree()
 {
     $root = JchPlatformPaths::rootPath();
     $dir = urldecode(JchPlatformUtility::get('dir', '', 'string', 'post'));
     $dir = JchPlatformUtility::decrypt($dir);
     $response = '';
     if (file_exists($root . $dir)) {
         $files = scandir($root . $dir);
         natcasesort($files);
         if (count($files) > 2) {
             /* The 2 accounts for . and .. */
             $response .= '<ul class="jqueryFileTree" style="display: none; ">';
             // All dirs
             foreach ($files as $file) {
                 if (file_exists($root . $dir . $file) && $file != '.' && $file != '..' && is_dir($root . $dir . $file)) {
                     $response .= '<li class="directory collapsed"><a href="#" rel="' . JchPlatformUtility::encrypt($dir . $file . '/') . '">' . htmlentities($file) . '</a></li>';
                 }
             }
             // All files
             foreach ($files as $file) {
                 if (file_exists($root . $dir . $file) && $file != '.' && $file != '..' && !is_dir($root . $dir . $file)) {
                     $ext = preg_replace('/^.*\\./', '', $file);
                     $response .= '<li class="file ext_' . $ext . '"><a href="#" rel="' . JchPlatformUtility::encrypt($dir . $file) . '">' . htmlentities($file) . '</a></li>';
                 }
             }
             $response .= '</ul>';
         }
     }
     return $response;
 }
开发者ID:sam-akopyan,项目名称:hamradio,代码行数:34,代码来源:ajax.php

示例3: recurse

/**
 * Recursively processes a path and extracts JSDoc comment data from
 * every .js file it finds.
 * @param $path
 */
function recurse($path)
{
    $fList = scandir($path);
    foreach ($fList as $key => $val) {
        switch ($val) {
            case '.':
            case '..':
                // Ignore these entries
                break;
            default:
                if (is_dir($path . '/' . $val)) {
                    // The entry is a folder so recurse it
                    recurse($path . '/' . $val);
                } else {
                    // The entry is a file, check if it's a .js file
                    if (substr($val, strlen($val) - 3, 3) === '.js') {
                        // Process the JS file
                        echo 'Processing JavaScript file: ' . $path . '/' . $val . '<BR>';
                        $data = parseFile($path . '/' . $val);
                        processData($data, $path . '/' . $val, $val);
                    }
                }
                break;
        }
    }
}
开发者ID:ParallaxMaster,项目名称:ige,代码行数:31,代码来源:generate.php

示例4: saveCorrectDataWithReflection

 public static function saveCorrectDataWithReflection()
 {
     $defaultControllerPath = "controllers\\defaultControllers\\";
     $controllerFileNames = scandir($defaultControllerPath, 1);
     $settingsArrayWithAllControllersAndActions = [];
     $num = 0;
     foreach ($controllerFileNames as $item) {
         $fileName = "controllers\\defaultControllers\\" . $item;
         if (strpos($item, "Controller")) {
             $clasFileName = substr($fileName, 0, -4);
             require_once $fileName;
             $currentClass = new $clasFileName();
             $reflection = new \ReflectionClass($currentClass);
             $methods = $reflection->getMethods();
             foreach ($methods as $i => $method) {
                 $docBlock = $method->getDocComment();
                 $pattern = "/Route\\(([A-Za-z]+)\\/([A-Za-z]+)\\)/";
                 preg_match($pattern, $docBlock, $routeMatch);
                 if (count($routeMatch) > 0) {
                     $objectToSave = (object) array("Controller" => $reflection->getName(), "Action" => $method->getName(), "CustomController" => $routeMatch[1], "CustomAction" => $routeMatch[2]);
                     $num++;
                     array_push($settingsArrayWithAllControllersAndActions, $objectToSave);
                     //echo '<pre>'; print_r($objectToSave); echo '</pre>';
                 }
             }
         }
     }
     $fp = fopen('config/customRoutes.json', 'w');
     fwrite($fp, json_encode($settingsArrayWithAllControllersAndActions));
     fclose($fp);
     //        echo '<pre>';
     //        print_r( json_encode($objectToSave));
     //        echo '</pre>';
 }
开发者ID:phkolarov,项目名称:Conference-Scheduler,代码行数:34,代码来源:AnnotationRoute.php

示例5: loadAll

 protected function loadAll()
 {
     $files = array_diff(scandir(JS_PATH . 'classes/'), array('..', '.'));
     foreach ($files as $file) {
         $this->template .= file_get_contents(JS_PATH . 'classes/' . $file);
     }
 }
开发者ID:Mlin3,项目名称:Simple-chat,代码行数:7,代码来源:JsTemplater.php

示例6: _recurseFolders

 function _recurseFolders($path)
 {
     if ($this->showsearch) {
         echo '<li>' . basename(realpath($path)) . '<ul>';
     }
     $files = scandir($path);
     static $s_count = 0;
     foreach ($files as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         $file_path = $path . '/' . $file;
         if (is_dir($file_path)) {
             if ($file != 'CVS' && !in_array($file_path, $this->ignorefolders)) {
                 $this->_recurseFolders($file_path);
             }
         } elseif (preg_match('/simpletest(\\/|\\\\)test.*\\.php$/', $file_path) || $this->thorough && preg_match('/simpletest(\\/|\\\\)slowtest.*\\.php$/', $file_path)) {
             $s_count++;
             // OK, found: this shows as a 'Notice' for any 'simpletest/test*.php' file.
             $this->addTestCase(new FindFileNotice($file_path, 'Found unit test file, ' . $s_count));
             // addTestFile: Unfortunately this doesn't return fail/success (bool).
             $this->addTestFile($file_path, true);
         }
     }
     if ($this->showsearch) {
         echo '</ul></li>';
     }
     return $s_count;
 }
开发者ID:veritech,项目名称:pare-project,代码行数:29,代码来源:ex_simple_test.php

示例7: w_rmdir_recursive_inner

function w_rmdir_recursive_inner($path)
{
    # avoid opening a handle on the dir in case that impacts
    # delete latency on windows
    if (@rmdir($path) || @unlink($path)) {
        return true;
    }
    clearstatcache();
    if (is_dir($path)) {
        # most likely failure reason is that the dir is not empty
        $kids = @scandir($path);
        if (is_array($kids)) {
            foreach ($kids as $kid) {
                if ($kid == '.' || $kid == '..') {
                    continue;
                }
                w_rmdir_recursive($path . DIRECTORY_SEPARATOR . $kid);
            }
        }
        if (is_dir($path)) {
            return @rmdir($path);
        }
    }
    if (is_file($path)) {
        return unlink($path);
    }
    return !file_exists($path);
}
开发者ID:iamchenxin,项目名称:watchman,代码行数:28,代码来源:WatchmanDirectoryFixture.php

示例8: file_upload

function file_upload($html)
{
    // Define wp upload folder
    $main_path = wp_upload_dir();
    $current_path = '';
    // Instaniate Post_Get class
    $get = new Post_Get();
    // Check if GET variable has value
    $get->exists('GET');
    $current_path = $get->get('upload_dir');
    // Define the folder directory that will hold the content
    $container = $main_path['basedir'] . '/upload_dir';
    // Create upload_dir folder to hold the documents that will be uploaded
    if (!file_exists($container)) {
        mkdir($container, 0755, true);
    }
    // Define current url
    $current_url = $main_path['baseurl'] . '/upload_dir/';
    // Scan current directory
    $current_dir = scandir($main_path['basedir'] . '/upload_dir/' . $current_path);
    // Wrap the retusts in unordered list
    $html .= "<ul>";
    // Loop throught current folder
    foreach ($current_dir as $file) {
        if (stripos($file, '.') !== 0) {
            if (strpos($file, '.html') > -1) {
                $html .= '<li><a href="' . $current_url . $current_path . '/' . $file . '">' . $file . '</a></li>';
            } else {
                $html .= '<li><a href="?upload_dir=' . $current_path . '/' . $file . '">' . $file . '</a></li>';
            }
        }
    }
    $html .= '</ul>';
    return $html;
}
开发者ID:mussealani,项目名称:uppload-files,代码行数:35,代码来源:upload-file.php

示例9: delete

 public function delete($path)
 {
     if (!is_dir($path)) {
         return false;
     }
     $path = self::path($path);
     $items = scandir($path);
     if (!is_array($items)) {
         return true;
     }
     foreach ($items as $v) {
         if ($v == '.' || $v == '..') {
             continue;
         }
         $v = $path . $v;
         if (is_dir($v)) {
             self::delete($v);
         } else {
             if (!@unlink($v)) {
                 throw new RuntimeException(sprintf('Folder::delete can not delete file %s', $v));
             }
         }
     }
     if (!@rmdir($path)) {
         throw new RuntimeException(sprintf('Folder::delete can not rmdir %s', $path));
     }
     return true;
 }
开发者ID:xudianyang,项目名称:yafrk-lib,代码行数:28,代码来源:Folder.php

示例10: build_mod_list

function build_mod_list()
{
    $sel_modules = array(array('id' => 'all', 'text' => TEXT_ALL), array('id' => 'install', 'text' => 'install'), array('id' => 'soap', 'text' => 'soap'));
    $dirs = scandir(DIR_FS_MODULES);
    foreach ($dirs as $value) {
        if ($value == '.' || $value == '..') {
            continue;
        }
        if (is_dir(DIR_FS_MODULES . $value . '/dashboards')) {
            // there are dashboards to load languages
            $meths = scandir(DIR_FS_MODULES . $value . '/dashboards');
            foreach ($meths as $val) {
                if ($val == '.' || $val == '..') {
                    continue;
                }
                $sel_modules[] = array('id' => $value . '-' . $val, 'text' => $value . '-' . $val);
            }
        }
        if (is_dir(DIR_FS_MODULES . $value . '/methods')) {
            // there are methods to load languages
            $meths = scandir(DIR_FS_MODULES . $value . '/methods');
            foreach ($meths as $val) {
                if ($val == '.' || $val == '..') {
                    continue;
                }
                $sel_modules[] = array('id' => $value . '-' . $val, 'text' => $value . '-' . $val);
            }
        }
        $sel_modules[] = array('id' => $value, 'text' => $value);
    }
    return $sel_modules;
}
开发者ID:siwiwit,项目名称:PhreeBooksERP,代码行数:32,代码来源:translator.php

示例11: get_files

 public static function get_files($path, $mask = NULL, $appendPath = false)
 {
     // objects
     $files = array();
     //$path		= preg_replace('%/+$%', '/', $path . '/'); // add trailing slash
     $objects = array_diff(scandir($path), array('.', '..'));
     // mask
     if ($mask != NULL) {
         // regular expression for detecing a regular expression
         $rxIsRegExp = '/^([%|\\/]|{).+(\\1|})[imsxeADSUXJu]*$/';
         // an array of file extenstions
         if (is_array($mask)) {
             $mask = '%\\.(' . implode('|', $mask) . ')$%i';
         } else {
             if (!preg_match($rxIsRegExp, $mask)) {
                 $mask = "/\\.{$mask}\$/i";
             }
         }
     }
     // match
     foreach ($objects as $object) {
         if (is_file($path . $object) && ($mask != NULL ? preg_match($mask, $object) : TRUE)) {
             array_push($files, $appendPath ? $path . $object : $object);
         }
     }
     // return
     return $files;
 }
开发者ID:riartem,项目名称:kohana-update,代码行数:28,代码来源:Filesystem.php

示例12: collectFiles

 public static function collectFiles($directory, $files)
 {
     $listings = scandir($directory);
     foreach ($listings as $listing) {
         $path = "{$directory}/{$listing}";
         if ($listing == '.' || $listing == '..') {
             continue;
         }
         // no hidden files or directories
         if (strpos($listing, ".") === 0) {
             continue;
         }
         // recursively scan directories
         if (is_dir($path)) {
             $files = Appcelerator_Service::collectFiles($path, $files);
         }
         // service files must be named [^.](.+)Service.php
         if (!stristr($listing, 'Service')) {
             continue;
         }
         // this is a valid service source file - record path and file name
         $files[$path] = Appcelerator_Service::fileToClassName($listing);
     }
     return $files;
 }
开发者ID:appcelerator,项目名称:entourage,代码行数:25,代码来源:Service.php

示例13: scan

function scan($dir)
{
    $files = array();
    // Is there actually such a folder/file?
    if (file_exists($dir)) {
        $scanned = scandir($dir);
        //get a directory listing
        $scanned = array_diff(scandir($dir), array('.', '..', '.DS_Store', 'Thumbs.db'));
        //sort folders first, then by type, then alphabetically
        usort($scanned, create_function('$a,$b', '
			return	is_dir ($a)
				? (is_dir ($b) ? strnatcasecmp ($a, $b) : -1)
				: (is_dir ($b) ? 1 : (
					strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION)) == 0
					? strnatcasecmp ($a, $b)
					: strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION))
				))
			;
		'));
        foreach ($scanned as $f) {
            if (!$f || $f[0] == '.') {
                continue;
                // Ignore hidden files
            }
            if (is_dir($dir . '/' . $f)) {
                // The path is a folder
                $files[] = array("name" => $f, "type" => "folder", "path" => $dir . '/' . $f, "items" => scan($dir . '/' . $f));
            } else {
                // It is a file
                $files[] = array("name" => $f, "type" => "file", "ext" => pathinfo($f, PATHINFO_EXTENSION), "path" => $dir . '/' . $f, "size" => filesize($dir . '/' . $f));
            }
        }
    }
    return $files;
}
开发者ID:vkynchev,项目名称:KynchevIDE,代码行数:35,代码来源:scan.php

示例14: get_file

/**
 * gets all the files in a directory
 * @param $directory    the directory to scan
 * @param $dl           i actually don't know?????? sorry been a while lol
 * @return              a list of html div elements (class=fileicon) 
 * @return              "There are no files in directory" if no files are in directory
 */
function get_file($directory, $dl)
{
    $files_list = "";
    $dir = $directory;
    // the directory you want to check
    $exclude = array(".", "..");
    // you don't want these entries in your files array
    $files = scandir($dir);
    $files = array_diff($files, $exclude);
    // delete the entries in exclude array from your files array
    if (!empty($files) and $dl) {
        foreach ($files as $file) {
            // print every file in the files array
            $files_list .= "<div class='fileicon'>\n\t\t<a href='{$directory}/{$file}' download>\n\t\t<p class='filetext'>{$file}</p>\n\t\t</a>\n\t\t</div>";
        }
    } else {
        if (!empty($files)) {
            foreach ($files as $file) {
                // print every file in the files array
                $files_list .= " <div class='fileicon'>\n\t<a href='{$directory}{$file}'>\n\t<p class='filetext'>{$file}</p>\n\t</a>\n\t</div>";
            }
        } else {
            $files_list .= "There are no files in directory";
            // print error message if there are no files
        }
    }
    return $files_list;
}
开发者ID:rei2hu,项目名称:php_functions,代码行数:35,代码来源:list_files.php

示例15: group_exports

/**
 * Scan the exports directory, return the files grouped into intervals of 3 minutes, newest first.
 *
 * @param string $dir fullpath to the Exports folder. (optional)
 * @return array
 */
function group_exports($dir = null)
{
    $ignored = array('.', '..', '.svn', '.git', '.htaccess');
    if (!$dir) {
        $dir = \PressBooks\Modules\Export\Export::getExportFolder();
    } else {
        $dir = rtrim($dir, '/') . '/';
    }
    $files = array();
    foreach (scandir($dir) as $file) {
        if (in_array($file, $ignored)) {
            continue;
        }
        $files[$file] = filemtime($dir . $file);
    }
    arsort($files);
    $interval = 3 * 60;
    // Three minutes
    $pos = 0;
    $output = array();
    foreach ($files as $file => $timestamp) {
        if (0 == $pos) {
            $pos = $timestamp;
        }
        if ($pos - $timestamp > $interval) {
            $pos = $timestamp;
        }
        $output[$pos][] = $file;
    }
    return $output;
}
开发者ID:cumi,项目名称:pressbooks,代码行数:37,代码来源:pb-utility.php


注:本文中的scandir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。