corneltek/xfile

快速文件实用工具扩展

安装: 6

依赖: 0

建议者: 0

安全: 0

星标: 10

关注者: 3

分支: 0

公开问题: 0

语言:C

dev-master / 1.0.x-dev 2015-12-07 09:39 UTC

This package is auto-updated.

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


README

Build Status

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

安装

安装PHP扩展

git clone https://github.com/c9s/xfile.git
cd xfile
phpize && ./configure --enable-xfile
make && make install

使用phpbrew安装

phpbrew ext install github:c9s/xfile

使用composer安装纯PHP版本

composer require "corneltek/xfile" "1.0.x-dev"

概要

$filelist = xfile_scanpath("/etc");

$dirlist = xfile_scanpath_dir("/etc");

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

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

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

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

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


// copy file if destination does not exist.
xfile_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",
);
xfile_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 === xfile_rmtree("/path/to/delete") ) {

}

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

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

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


$dirs = xfile_paths_filter_dir($allfiles);

$files = xfile_paths_filter_files($allfiles);

用法

path[] xfile_scanpath($dir)

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

$list = xfile_scanpath('/etc');

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

path[] xfile_scanpath_dir($dir)

xfile_scanpath($dir) 相同,但 xfile_scanpath_dir 只返回目录条目。

long xfile_lastmtime($filelist)

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

long xfile_lastctime($filelist)

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

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

array xfile_pathsplit($path)

xfile_unlink_if_exists($path)

xfile_rmdir_if_exists($path)

xfile_mkdir_if_not_exists($path)

xfile_rmtree($path)

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

xfile_paths_prepend($paths, $prepend)

xfile_paths_append($paths, $append)

xfile_replace_extension($path, $newExtension)

xfile_get_extension($path)

xfile_filename_append_suffix($path, $suffix)

黑客开发

  • 分支此项目。

  • 克隆git仓库。

    phpize ./configure make make test

作者

Yo-An Lin yoanlin93@gmail.com

许可证

MIT许可证(见LICENSE文件)