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);
}
}