当前位置:网站首页>[symfony/finder] The best file manipulation library
[symfony/finder] The best file manipulation library
2022-08-02 03:55:00 【phpreturn】
Sometimes, we need to operate the files on the server, either traverse the directory or find the corresponding extension files. At this time, the code we found on the Internet is very bad. Is there an elegant high-performance one?How?
finder is one such library.
Basic usage
use Symfony\Component\Finder\Finder;$finder = new Finder();// go to a folder$finder->files()->in(__DIR__);// check if it is emptyif ($finder->hasResults()) {// ...}foreach ($finder as $file) {// start traversing the file$absoluteFilePath = $file->getRealPath();$fileNameWithExtension = $file->getRelativePathname();// ...}Elegant Filtered Search
Calling the in method in a chain means looking for another directory under a certain directory.
$finder->in(__DIR__)->in('/elsewhere');Match the corresponding file by *
$finder->in('src/Symfony/*/*/Resources');Exclude some files
$finder->in(__DIR__)->exclude('ruby');Directly filter out files that do not have permission to read
$finder->ignoreUnreadableDirs()->in(__DIR__);Support various underlying systems
Support access to standard file protocols
// Open an FTP address$finder->in('ftp://example.com/');$finder->in('ftp://example.com/pub/');The following access methods are supported:
- file:// — access the local file system
- http:// — Access HTTP(s) URL
- ftp:// — Access FTP(s) URLs
- php:// — access each input/I/O streams
- zlib:// — Compressed Streamli>
- data:// — Data (RFC 2397)
- glob:// — find matching filesPath Pattern
- phar:// — PHP Archiveli>
- ssh2:// — Secure Shell 2
- rar:// — RAR
- ogg:// — Audio Streamingli>
- expect:// — handles interactiveStream
Supports custom underlying system protocols, the following example shows access to Amazon's storage.
use Symfony\Component\Finder\Finder;// Register access protocol through AWS official package 's3://'$s3Client = new Aws\S3\S3Client([/* config options */]);$s3Client->registerStreamWrapper();$finder = new Finder();$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');foreach ($finder->in('s3://bucket-name') as $file) {// ... do something with the file}Easy to manipulate files or directories
// only query files$finder->files();// only query the directory$finder->directories();Filter files
Supports a very elegant way of manipulating files.
$finder->files()->name('*.php');$finder->files()->name('/\.php$/');$finder->files()->notName('*.rb');$finder->files()->size('>= 1K')->size('<= 2K');$finder->date('>= 2018-01-01')->date('<= 2018-12-31');边栏推荐
- 1.6一些今日学习
- (2)Thinkphp6模板引擎**标签
- IO流、 编码表、 字符流、 字符缓冲流
- 线程池(线程池介绍与使用)
- 数组的高级操作
- TCP communications program
- Function hoisting and variable hoisting
- Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
- Query the indexes of all tables in the database and parse them into sql
- Phpstudy installs Thinkphp6 (problem + solution)
猜你喜欢
![[sebastian/diff]一个比较两段文本的历史变化扩展库](/img/c7/ea79db7a5003523ece7cf4f39e4987.png)
[sebastian/diff]一个比较两段文本的历史变化扩展库

6.27面试集

SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration

(3) Thinkphp6 database

IP access control: teach you how to implement an IP firewall with PHP

解决5+APP真机测试无法访问后台(同局域网)

vue3 访问数据库中的数据
![[league/climate] A robust command-line function manipulation library](/img/ce/39114b1c74af649223db97e5b0e29c.png)
[league/climate] A robust command-line function manipulation library

三元判断再三元判断

TCP communications program
随机推荐
每日五道面试题 2022/7/27
3. PHP data types, constants, strings and operators
--fs module--
PHP入门(自学笔记)
ES6三点运算符、数组方法、字符串扩展方法
js的“类数组”及“类数组转数组”
14.JS语句和注释,变量和数据类型
解决 Zlibrary 卡死/找不到域名/达到限额问题,Zlibrary最新地址
TypeScript 错误 error TS2469、error TS2731 解决办法
AES加密的各种蛋疼方式方式
PHP的几个有趣的打开方式:从基本到变态
Baidu positioning js API
About the apache .htaccess file of tp
1.10今日学习
轮播图详解(完整代码在最后)
Using PHPMailer send mail
---static page---
Advanced Operations on Arrays
16. JS events, string and operator
1.13 学习JS