corneltek/fileutil

此包的最新版本(1.7.1)没有可用的许可证信息。

快速文件工具扩展

安装次数: 13,146

依赖项: 11

建议者: 0

安全: 0

星星: 8

关注者: 3

分支: 0

公开问题: 0

语言:C

1.7.1 2013-09-18 15:00 UTC

This package is auto-updated.

Last update: 2024-08-29 03:06:14 UTC


README

Build Status

快速文件工具扩展(支持纯PHP实现)

FileUtil 扩展提供了一种高效操作文件相关操作的方式。

安装

安装 PHP 扩展

git clone https://github.com/c9s/php-fileutil.git
cd php-fileutil
phpize
./configure
make
make install
phpbrew ext enable fileutil # if you use phpbrew

安装纯 PHP 实现

$ pear channel-discover pear.corneltek.com
$ pear install corneltek/FileUtil

概要

$filelist = futil_scanpath("/etc");

$dirlist = futil_scanpath_dir("/etc");

$path = futil_pathjoin("etc","folder","file1"); 
// which returns "etc/folder/file1", as the same as "etc" . DIRECTORY_SEPARATOR . "folder" . DIRECTORY_SEPARATOR . "file1"

$subpaths  = futil_pathsplit("etc/folder/file1");

// replace current extension with another extension.
$newFilename = futil_replace_extension("manifest.yml","json"); // Returns manifest.json

// get extension from the filename.
$extension = futil_get_extension("manifest.yml");   // Returns "yml"

// copy file if the mtime of source is newer than the mtime of destination.
futil_copy_if_newer("source_file","target_file");


// copy file if destination does not exist.
futil_copy_if_not_exists("source_file", "target_file");


// prepend path to an array that contains paths.
$filelist = array(
    "file1",
    "file2",
    "path2/file3",
    "path3/file4",
    "path4/file5",
);
futil_paths_prepend($filelist, "/root");
/* $filelist = array(
    "/root/file1",
    "/root/file2",
    "/root/path2/file3",
    "/root/path3/file4",
    "/root/path4/file5",
);
*/


// clean up whole directory
if ( false === futil_rmtree("/path/to/delete") ) {

}

$newfilename = futil_filename_append_suffix("Picture.png", "_suffix");  // Returns "Picture_suffix.png"
$newfilename = futil_filename_append_suffix("Picture", "_suffix");  // Returns "Picture_suffix"

$content = futil_get_contents_from_files(array("file1","file2","file3"));

$contents = futil_get_contents_array_from_files(array("config.m4","php_fileutil.c"));
foreach( $contents as $content ) {
    echo $content['path'];
    echo $content['content'];
}


$dirs = futil_paths_filter_dir($allfiles);

$files = futil_paths_filter_files($allfiles);

用法

path[] futil_scanpath($dir)

其行为与内置函数 scandir($dir) 不同,futil_scanpath 将项目与基本路径连接,并过滤掉 "." 和 ".." 路径。

$list = futil_scanpath('/etc');

/*
array( 
    '/etc/af.plist',
    '/etc/afpovertcp.cfg',
    '/etc/asl.conf',
);
*/

path[] futil_scanpath_dir($dir)

futil_scanpath($dir) 相同,但 futil_scanpath_dir 只返回目录条目。

long futil_lastmtime($filelist)

这从文件列表数组返回最后修改时间。

long futil_lastctime($filelist)

这从文件列表数组返回最后创建时间。

string futil_pathjoin($path1, $path2, $path3)

array futil_pathsplit($path)

futil_unlink_if_exists($path)

futil_rmdir_if_exists($path)

futil_mkdir_if_not_exists($path)

futil_rmtree($path)

通过 RecursiveDirectoryIterator 递归删除文件和目录。

futil_paths_prepend($paths, $prepend)

futil_paths_append($paths, $append)

futil_replace_extension($path, $newExtension)

futil_get_extension($path)

futil_filename_append_suffix($path, $suffix)

黑客攻击

  • 分叉此项目。

  • 克隆 git 仓库。

  • 在仓库下运行命令

      pear channel-discover pear.corneltek.com
      pear channel-update -f corneltek
      pear install -f corneltek/Universal
      pear install -f corneltek/PHPUnit_TestMore
      pear install -f corneltek/PHPUnit_Framework_ExtensionTestCase
      pear install -f corneltek/ExtUnit
      phpize
      ./configure
      make
    
  • 运行 extunit 测试扩展函数

      extunit --phpunit
    
  • 运行 phpunit 测试纯 PHP 函数

      phpunit
    

作者

Pedro cornelius.howl@gmail.com

许可证

查看 LICENSE 文件。