|  Download FilesystemEsi\Utility\Filesystem
 @access private// Helper functions for lineCounter(), directorySize(), directoryList()
getIterator(string $forDirectory, bool $keyAsPath = false): RecursiveIteratorIterator
buildIgnore(array $ignore): string
checkIgnore(string $path, string $ignore): bool
checkExtensions(string $extension, array $extensions): bool
 lineCounterParse a given directory's files for an approximate line count. Could be used for a project directory, for example, to determine the line count for a project's codebase. use Esi\Utility\Filesystem;
/
 * For this example, let's say '/some/directory' has 3 files:
 *    file1
 *    file2
 *    file3.txt
 *
 * ... and 'file1' has 5 lines.
 */
$directory = '/some/directory';
print_r(Filesystem::lineCounter($directory));
/*
Array (
    '/some/directory' => Array (
        'file1' => 0,
        'file2' => 0,
        'file3.txt' => 5
    )
)
*/
 directorySizeRetrieves size of a directory (in bytes). use Esi\Utility\Filesystem;
/
 * For this example, let's say '/some/directory' has 2 files:
 *    file1 with content '1234567890'
 *    file2 with content 'abcdefghijklmnopqrstuvwxyz'
 */
$directory = '/some/directory';
echo Filesystem::directorySize($directory); // 36
 directoryListRetrieves contents of a directory. use Esi\Utility\Filesystem;
/
 * For this example, let's say '/some/directory' has 2 files:
 *    file1
 *    file2
 */
$directory = '/some/directory';
print_r(Filesystem::directoryList($directory));
/*
Array (
    0 => '/some/directory/file1',
    1 => '/some/directory/file2',
)
*/
 normalizeFilePathNormalizes a file or directory path. use Esi\Utility\Filesystem;
$separator = DIRECTORY_SEPARATOR;
$path1 = $separator . 'some' . $separator . 'directory' . $separator . 'file1';
echo Filesystem::normalizeFilePath($path1); // /some/directory/file1
$path2 = '\\//some\\//directory\\//file1';
echo Filesystem::normalizeFilePath($path2); // /some/directory/file1
 isReallyWritableChecks to see if a file or directory is really writable. use Esi\Utility\Filesystem;
$file = '/this/file/exists_writable.txt';
var_dump(Filesystem::isReallyWritable($file)); // bool(true)
 fileReadPerform a read operation on a pre-existing file. use Esi\Utility\Filesystem;
// This is essentially a wrapper around 'file_get_contents' that will throw an exception if not a file.
echo Filesystem::fileRead('/some/directory/file1'); // '1234567890'
 fileWritePerform a write operation on a pre-existing file. use Esi\Utility\Filesystem;
// A wrapper around 'file_put_contents' that checks file existence and its writability.
echo Filesystem::fileWrite('/some/directory/file1', "This is a test."); // 15
 isFileDetermines if the given $file is both a file and readable. // Just combines 'is_file' and 'is_readable' checks.
 isDirectoryDetermines if the given $directory is both a directory and readable. // Just combines 'is_dir' and 'is_readable' checks.
 |