本文整理汇总了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);
}
}
示例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;
}
示例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;
}
}
}
示例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>';
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}