2017 © Pedro Peláez
 

library fileutil

Fast File Utility Extension

image

corneltek/fileutil

Fast File Utility Extension

  • Monday, September 23, 2013
  • by c9s
  • Repository
  • 1 Watchers
  • 6 Stars
  • 12,030 Installations
  • C
  • 11 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

FileUtil Extension

Build Status, (*1)

Fast File Utility Extension (with Pure PHP Implementation Support), (*2)

FileUtil Extension provides an efficient way to operate file related operations., (*3)

Installation

Install the PHP extension:, (*4)

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

Install the pure PHP implementation:, (*5)

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

Synopsis

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

Usage

path[] futil_scanpath($dir)

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

$list = futil_scanpath('/etc');

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

path[] futil_scanpath_dir($dir)

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

long futil_lastmtime($filelist)

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

long futil_lastctime($filelist)

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

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

array futil_pathsplit($path)

futil_rmdir_if_exists($path)

futil_mkdir_if_not_exists($path)

futil_rmtree($path)

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

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)

Hacking

  • Fork this project.
  • Clone the git repository.
  • Run commands under the repository:, (*11)

    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
  • Run extunit to test extension functions:, (*12)

    extunit --phpunit
  • Run phpunit to test pure php functions:, (*13)

    phpunit

Author

Pedro cornelius.howl@gmail.com, (*14)

License

See LICENSE file., (*15)

The Versions

23/09 2013

dev-master

9999999-dev

Fast File Utility Extension

  Sources   Download

The Development Requires

18/09 2013

1.7.1

1.7.1.0

Fast File Utility Extension

  Sources   Download

The Development Requires

19/06 2013

1.7.0

1.7.0.0

Fast File Utility Extension

  Sources   Download

The Development Requires

24/03 2013

1.6.4

1.6.4.0

Fast File Utility Extension

  Sources   Download

The Development Requires

24/03 2013

1.6.3

1.6.3.0

Fast File Utility Extension

  Sources   Download

The Development Requires

24/03 2013

1.6.2

1.6.2.0

  Sources   Download

21/03 2013

1.6.1

1.6.1.0

Fast File Utility Extension

  Sources   Download

The Development Requires

18/03 2013

1.6.0

1.6.0.0

Fast File Utility Extension

  Sources   Download

18/03 2013

dev-develop

dev-develop

Fast File Utility Extension

  Sources   Download