PHP code example of myttyy / directory-file

1. Go to this page and download the library: Download myttyy/directory-file library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

myttyy / directory-file example snippets


composer 



namespace app\api\controller;

use think\facade\Env;

use myttyy\FilesFinder;
use myttyy\Directory;
use myttyy\File;

class Test
{
    public function index(){

        $list1 = (new FilesFinder())->select(["*[0-9]*.log"],[Env::get('runtime_path')])->select();
        var_dump($list1->toArray());
        $list2 = (new FilesFinder())->findFiles("*[0-9]*.log")->from(Env::get('runtime_path'))->date(">=2019-04-29 18:07:19");
        var_dump($list2->toArray());
        $list3 = (new FilesFinder())->findFiles("*[0-9]*.log")->from(Env::get('runtime_path'))->size('>2Mb');
        var_dump($list3->toArray());
        $list4 = (new FilesFinder())->select(["*.log"],[Env::get('runtime_path')])->exclude("cli.log");
        foreach ($list4 as $key => $value) {
          var_dump($value);
        }


        $tree = Directory::tree(Env::get('runtime_path'));
        var_dump($tree);


        $line = File::getFileLine(Env::get('runtime_path')."/log/201804/30.log",0);
        var_dump($line);
    }
}

    Directory::create(string $dir,int $auth = 0755 )
    

    Directory::copy(string $old,string $new )
    

    Directory::move(string $old,string $new )
    

     Directory::del(string $dir )
    

    Directory::size(string $dir )
    

    Directory::sizeFormatFielBytes(string $dir )
    

    File::copyFile(string $file,int $auth = 0755 )
    

    File::moveFile(string $file,int $auth = 0755 )
    

    File::delFile(string $file,int $auth = 0755 )
    

    File::getFileLine(string $file,int $line )
    

    FilesFinder::select($pattern=null,$paths=null)
    

    FilesFinder::find(...$pattern) //
    

    FilesFinder::findFiles(...$pattern);
    

    FilesFinder::notFilesInfo()
    

    FilesFinder::maxDepth(int $maxDepth);
    

    // $paths:目录路径 支持一维数组 in(["/public","/log"]) 也支持不定参数 in("/public","/log");
    FilesFinder::in(...$paths);
    

    // $paths:目录路径 支持一维数组 in(["/public","/log"]) 也支持不定参数 in("/public","/log");
    FilesFinder::from(...$paths);
    

    // eg: FilesFinder::exclude("abc") 将排除文件路径含有abc的文件
    FilesFinder::exclude();

    

    // eg: FilesFinder::size(">=100kb") 比较符号键下表
    FilesFinder::size(string $operator); 
    

    // eg: FilesFinder::date(">=2019-04-30 16:46:57")
    FilesFinder::date(string $operator);
    

        FilesFinder::toArray()