目录操作_PHP
即兴写的代码,大家可以完善一下
/**
* DirTree.php 递归列出目录
*
* @Copyright
* @Author skyCrack
* @Created
* @Version $Id$
*/
define('_DEBUG', 1);
class DirTree
{
private $_dirRoot;
private $_filter;
private $_tmpBuff = array();
public function __construct($dirRoot = '.')
{
$this->_dirRoot = $dirRoot;
}
//使用 过滤器 或者 设置 $_safeFile ....
public function setFilter($filter)
{
$this->_filter = $filter;
}
public function listDirFile($dir = '', $action='')
{
$curDir = ( empty($dir) ) ? $this->_dirRoot : $dir;
$dh = @opendir($curDir);
while ( $tmpName = readdir($dh) )
{
if ( ($tmpName == '.') || ($tmpName == '..') ) continue;
$totalPath = $curDir . '/' . $tmpName;
if ( is_object($this->_filter) )
{
if ( $this->_filter->doFilter($totalPath) ) continue;
}
if ( is_dir($totalPath) )
{
$this->_tmpBuff['0'][] = $tmpName;
if ( _DEBUG )
{
echo 'is dir:' . $totalPath . '
';
}
if ( is_object($action) )
{
$action->doAction($totalPath);
}
$this->listDirFile($totalPath, $action);
}
else
{
$this->_tmpBuff['1'][] = $tmpName;
if ( _DEBUG )
{
echo 'is file:' . $totalPath . '
';
}
if ( is_object($action) )
{
$action->doAction($totalPath);
}
}
}
closedir($dh);
}
}
interface DirAction
{
public function doAction($args);
}
interface DirFilter
{
public function doFilter($args);
}
class NowAction implements DirAction
{
public function doAction($args)
{
if ( _DEBUG )
{
$numArgs = func_num_args();
echo $numArgs . '
';
for( $i = 0; $i print_r(func_get_arg($i) . '
');
}
}
}
=====================================================
应用 部分
set_time_limit(0);
require 'DirTree.php';
class Gbk2Utf8Action implements DirAction
{
public function doAction($args)
{
$aimPath = ereg_replace('D:/html/web','D:/back', $args);
if ( is_file($args) )
{
$file = implode ('', file($args));
$content = iconv("gb2312", "UTF-8", $file);
$fh = fopen($aimPath, 'w');
fwrite($fh, $content);
fclose($fh);
}
else
{
mkdir($aimPath);
}
}
}
class HtmlPhpFilter implements DirFilter
{
public function doFilter($args)
{
$suffix = substr(strrchr($args, '.'), 1);
if ( ('htm' == $suffix) || ('php' == $suffix) )
return false;
else if ( is_dir($args) )
return false;
else
return true;
}
}
$dirTree = new DirTree();
$action = new Gbk2Utf8Action();
$filter = new HtmlPhpFilter();
$dirTree->setFilter($filter);
$dirTree->listDirFile('D:/html/web', $action);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PyCharm is a very popular Python integrated development environment (IDE). It provides a wealth of functions and tools to make Python development more efficient and convenient. This article will introduce you to the basic operation methods of PyCharm and provide specific code examples to help readers quickly get started and become proficient in operating the tool. 1. Download and install PyCharm First, we need to go to the PyCharm official website (https://www.jetbrains.com/pyc

In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

LinuxDeploy operating steps and precautions LinuxDeploy is a powerful tool that can help users quickly deploy various Linux distributions on Android devices, allowing users to experience a complete Linux system on their mobile devices. This article will introduce the operating steps and precautions of LinuxDeploy in detail, and provide specific code examples to help readers better use this tool. Operation steps: Install LinuxDeploy: First, install

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

Presumably many users have several unused computers at home, and they have completely forgotten the power-on password because they have not been used for a long time, so they would like to know what to do if they forget the password? Then let’s take a look together. What to do if you forget to press F2 for win10 boot password? 1. Press the power button of the computer, and then press F2 when turning on the computer (different computer brands have different buttons to enter the BIOS). 2. In the bios interface, find the security option (the location may be different for different brands of computers). Usually in the settings menu at the top. 3. Then find the SupervisorPassword option and click it. 4. At this time, the user can see his password, and at the same time find the Enabled next to it and switch it to Dis.

With the popularity of smartphones, the screenshot function has become one of the essential skills for daily use of mobile phones. As one of Huawei's flagship mobile phones, Huawei Mate60Pro's screenshot function has naturally attracted much attention from users. Today, we will share the screenshot operation steps of Huawei Mate60Pro mobile phone, so that everyone can take screenshots more conveniently. First of all, Huawei Mate60Pro mobile phone provides a variety of screenshot methods, and you can choose the method that suits you according to your personal habits. The following is a detailed introduction to several commonly used interceptions:

Select the style of the catalog in Word, and it will be automatically generated after the operation is completed. Analysis 1. Go to Word on your computer and click to import. 2After entering, click on the file directory. 3 Then select the style of the directory. 4. After the operation is completed, you can see that the file directory is automatically generated. Supplement: The table of contents of the summary/notes article is automatically generated, including first-level headings, second-level headings and third-level headings, usually no more than third-level headings.
