PHP code example of popphp / pop-dir

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

    

popphp / pop-dir example snippets


use Pop\Dir\Dir;

$dir = new Dir('my-dir');

foreach ($dir->getFiles() as $file) {
    echo $file;
}

use Pop\Dir\Dir;

$dir = new Dir('my-dir', [
    'absolute'  => true,
    'recursive' => true
]);

foreach ($dir->getFiles() as $file) {
    echo $file;
}


$options = [
    'absolute'  => true,  // store the absolute, full path of the items in the directory
    'relative'  => false  // store the relative path of the items in the directory
    'recursive' => true,  // traverse the directory recursively
    'filesOnly' => false, // store only files in the object (and not other directories)
];

use Pop\Dir\Dir;

$dir = new Dir('my-dir');
$dir->emptyDir();

$dir->emptyDir(true);