2017 © Pedro Peláez
 

library xfile

Fast File Utility Extension

image

corneltek/xfile

Fast File Utility Extension

  • Monday, December 7, 2015
  • by c9s
  • Repository
  • 1 Watchers
  • 9 Stars
  • 0 Installations
  • C
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

xfile

Build Status, (*1)

Fast File Utility Extension (with pure PHP implementation support), (*2)

Installation

Install the PHP extension:, (*3)

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

Install with phpbrew:, (*4)

phpbrew ext install github:c9s/xfile

Install pure php version with composer:, (*5)

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

Synopsis

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

Usage

path[] xfile_scanpath($dir)

The behavior is different from the built-in function scandir($dir), xfile_scanpath concat the items with the base path, and it filters out "." and ".." paths., (*6)

$list = xfile_scanpath('/etc');

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

path[] xfile_scanpath_dir($dir)

As the same as xfile_scanpath($dir), but xfile_scanpath_dir only returns directory entries., (*7)

long xfile_lastmtime($filelist)

This returns the last modification time from a filelist array., (*8)

long xfile_lastctime($filelist)

This returns the last creation time from a filelist array., (*9)

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

array xfile_pathsplit($path)

xfile_rmdir_if_exists($path)

xfile_mkdir_if_not_exists($path)

xfile_rmtree($path)

Recursively delete files and directories through RecursiveDirectoryIterator., (*10)

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)

Hacking

  • Fork this project.
  • Clone the git repository., (*11)

    phpize ./configure make make test, (*12)

Author

Yo-An Lin yoanlin93@gmail.com, (*13)

License

MIT License (See LICENSE file), (*14)

The Versions

07/12 2015

dev-master

9999999-dev

Fast File Utility Extension

  Sources   Download

MIT

The Development Requires

by Avatar c9s