PHPackages                             corneltek/xfile - 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. corneltek/xfile

ActiveLibrary

corneltek/xfile
===============

Fast File Utility Extension

106C

Since Dec 7Pushed 10y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

xfile
=====

[](#xfile)

[![Build Status](https://camo.githubusercontent.com/ea6aedcbe4ab0e9d59fa71719a52a65cbea85ec1281e3e3dfde6c455e9a41eba/68747470733a2f2f7472617669732d63692e6f72672f6339732f7866696c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/c9s/xfile)

Fast File Utility Extension (with pure PHP implementation support)

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

[](#installation)

Install the PHP extension:

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

Install with phpbrew:

```
phpbrew ext install github:c9s/xfile
```

Install pure php version with composer:

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

Synopsis
--------

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

[](#usage)

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

[](#path-xfile_scanpathdir)

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.

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

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

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

[](#path-xfile_scanpath_dirdir)

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

#### `long xfile_lastmtime($filelist)`

[](#long-xfile_lastmtimefilelist)

This returns the last modification time from a filelist array.

#### `long xfile_lastctime($filelist)`

[](#long-xfile_lastctimefilelist)

This returns the last creation time from a filelist array.

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

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

#### `array xfile_pathsplit($path)`

[](#array-xfile_pathsplitpath)

#### `xfile_unlink_if_exists($path)`

[](#xfile_unlink_if_existspath)

#### `xfile_rmdir_if_exists($path)`

[](#xfile_rmdir_if_existspath)

#### `xfile_mkdir_if_not_exists($path)`

[](#xfile_mkdir_if_not_existspath)

#### `xfile_rmtree($path)`

[](#xfile_rmtreepath)

Recursively delete files and directories through RecursiveDirectoryIterator.

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

[](#xfile_paths_prependpaths-prepend)

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

[](#xfile_paths_appendpaths-append)

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

[](#xfile_replace_extensionpath-newextension)

#### `xfile_get_extension($path)`

[](#xfile_get_extensionpath)

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

[](#xfile_filename_append_suffixpath-suffix)

Hacking
-------

[](#hacking)

- Fork this project.
- Clone the git repository.

    phpize ./configure make make test

Author
------

[](#author)

Yo-An Lin

License
-------

[](#license)

MIT License (See LICENSE file)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### 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 (36 commits)")

### Embed Badge

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

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

PHPackages © 2026

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