PHPackages                             corneltek/fileutil - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. corneltek/fileutil

ActiveLibrary[File &amp; Storage](/categories/file-storage)

corneltek/fileutil
==================

Fast File Utility Extension

1.7.1(12y ago)813.3k↓66.7%10C

Since Mar 18Pushed 12y ago1 watchersCompare

[ Source](https://github.com/c9s/php-fileutil)[ Packagist](https://packagist.org/packages/corneltek/fileutil)[ RSS](/packages/corneltek-fileutil/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (10)

FileUtil Extension
==================

[](#fileutil-extension)

[![Build Status](https://camo.githubusercontent.com/a0c5c4825eec201dba73475d17e58e14214019aad05193cfd7a7773562377f6d/68747470733a2f2f7472617669732d63692e6f72672f6339732f7068702d66696c657574696c2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/c9s/php-fileutil)

Fast File Utility Extension (with Pure PHP Implementation Support)

FileUtil Extension provides an efficient way to operate file related operations.

Installation
------------

[](#installation)

Install the PHP extension:

```
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:

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

Synopsis
--------

[](#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
-----

[](#usage)

#### `path[] futil_scanpath($dir)`

[](#path-futil_scanpathdir)

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.

```
$list = futil_scanpath('/etc');

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

#### `path[] futil_scanpath_dir($dir)`

[](#path-futil_scanpath_dirdir)

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

#### `long futil_lastmtime($filelist)`

[](#long-futil_lastmtimefilelist)

This returns the last modification time from a filelist array.

#### `long futil_lastctime($filelist)`

[](#long-futil_lastctimefilelist)

This returns the last creation time from a filelist array.

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

[](#string-futil_pathjoinpath1-path2-path3)

#### `array futil_pathsplit($path)`

[](#array-futil_pathsplitpath)

#### `futil_unlink_if_exists($path)`

[](#futil_unlink_if_existspath)

#### `futil_rmdir_if_exists($path)`

[](#futil_rmdir_if_existspath)

#### `futil_mkdir_if_not_exists($path)`

[](#futil_mkdir_if_not_existspath)

#### `futil_rmtree($path)`

[](#futil_rmtreepath)

Recursively delete files and directories through RecursiveDirectoryIterator.

#### `futil_paths_prepend($paths, $prepend)`

[](#futil_paths_prependpaths-prepend)

#### `futil_paths_append($paths, $append)`

[](#futil_paths_appendpaths-append)

#### `futil_replace_extension($path, $newExtension)`

[](#futil_replace_extensionpath-newextension)

#### `futil_get_extension($path)`

[](#futil_get_extensionpath)

#### `futil_filename_append_suffix($path, $suffix)`

[](#futil_filename_append_suffixpath-suffix)

Hacking
-------

[](#hacking)

- Fork this project.
- Clone the git repository.
- Run commands under the repository:

    ```
      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:

    ```
      extunit --phpunit

    ```
- Run phpunit to test pure php functions:

    ```
      phpunit

    ```

Author
------

[](#author)

Pedro

License
-------

[](#license)

See LICENSE file.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~44 days

Total

7

Last Release

4625d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (278 commits)")

### Embed Badge

![Health badge](/badges/corneltek-fileutil/health.svg)

```
[![Health](https://phpackages.com/badges/corneltek-fileutil/health.svg)](https://phpackages.com/packages/corneltek-fileutil)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
