PHP code example of lukaswhite / directory

1. Go to this page and download the library: Download lukaswhite/directory 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/ */

    

lukaswhite / directory example snippets


$directory = new Directory( '/path/to/dir' );

if ( $directory->exists ) {
	// do something
}

if ( ! $directory->isDirectory( ) ) {
	// looks like it's a file!
}

$directory = new Directory( '/path/to/new/directory' );
$directory->create( );

$directory->create( 0755 );

$files = $directory->getFiles( );

$files = $directory->getFiles( true );

$files = $directory->getFiles( false, true );

$textFiles = $directory->glob( '*.txt' );

if ( $directory->fileExists( 'logo.png' ) ) {
	// do something
}

$recent = $directory->mostRecentFile( );

$recent = $directory->mostRecentFile( '*.txt' );

$size = $directory->totalSize( );

$directory = new Directory( '/path/to/avatars' );
$filename = $directory-> ensureUniqueFilename( 'joebloggs.png' );
// joebloggs-1.png
$filepath = $directory->fullPathToFile( $filename );
// /path/to/avatars/joebloggs-1.png

$directory->createFile( 'filename.txt' );

$directory->createFile( 'filename.txt', 'the contents' );

$directory->copyFileInto( '/path/to/your/file' );