norris1z/zing_finder

一个用于对文件和目录执行操作的灵活库

v1.0 2017-02-28 12:39 UTC

This package is auto-updated.

Last update: 2024-09-29 04:37:05 UTC


README

Zing Finder 是 Zing 框架(开发中)的一个组件,该框架提供了用于对文件和目录执行操作的流畅 API。

安装

可以通过克隆仓库 norris1z/Zing-Finder 或通过 Composer 安装 Zing Finder 到项目中。在终端中运行以下命令以通过 Composer 安装该包

composer require norris1z/zing_finder

使用方法

<?php

require 'vendor/autoload.php';
use Zing\Finder\Exceptions\DirectoryException;
use Zing\Finder\Finder;

try {

   //Path to the directory can be passed through the constructor or the setDirectory method.
    $file = new Finder('foo/bar/dir');
    
    //setting path to the directory through setDirectory
    $file->setDirectory('foo/bar/dir');
    
    // this scans through a directory 
    // it accepts a boolean parameter which is set to false by default
    // to scan through the directory and subdirectories in the directory set parameter to true
    var_dump($find->search()); // prints all files in the directory 
    var_dump($find->search(true)); //prints files in both directories and subdirectories 
    
    // finds and displays files in a directory given an extentsion 
    var_dump($find->findFilesWithExtension('extension')->show());
    
    //includes sub-directories
     var_dump($find->findFilesWithExtension('extension',true)->show());
    
    // finds and deletes files in a directory given an extentsion 
     $find->findFilesWithExtension('extension')->delete();
     
     //includes sub-directories
     $find->findFilesWithExtension('extension',true)->delete();
    
    // finds and copies files in a directory given an extentsion to another directory 
    $find->findFilesWithExtension('extension')->copy('foo/bar/dir');
    
    //includes sub-directories
     $find->findFilesWithExtension('extension',true)->copy('foo/bar/dir');
    
    //finds zip files in a given directory and extracts them to a given folder
    $find->findFilesWithExtension('zip')->extractTo('foo/bar/dir');
    
     //includes sub-directories
     $find->findFilesWithExtension('zip',true)->extractTo('foo/bar/dir');
    
}catch (DirectoryException $e){
    echo $e->getMessage();
}