PHP code example of corneltek / fileutil

1. Go to this page and download the library: Download corneltek/fileutil library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corneltek / fileutil example snippets


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

$list = futil_scanpath('/etc');

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