PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of GARCIA Jean-François   PHP ScanDir Files   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example use of Scandir Class
Class: PHP ScanDir Files
Get the list of files from a directory recursively
Author: By
Last change: Modifying the example file because change the Class php filename
Date: 10 years ago
Size: 2,293 bytes


Class file image Download
/* Example of use of the Scandir class */

// include the class ScanDir
include_once "Class_ScanDir.php";

// the path must be an absolute path without the end slash
// ei : $Path="/var/www/test";
$Path = "<your path to directory>";

// instantiate the class.
$Dir = new DirScan () ;

// if needed, set the filter of extension and activate it
// 1 / first define the filter : it will be an array of all extension you want,
// for example here : .php, .jpg, .gif
// in the array string, you only need to put the extension name without dot '.'
$Dir->SetFilterExt(array("php","jpg","gif")) ;
// 2 / just activate it or not. here, the filter is not activate by default.
// you just need to change 'false' by 'true' to enable the filter mode.

// enable the listing off all the extension of files found during scanning
// by specifying true, the scan will keep in an array, all the unique extension
// found during process. this array can be different of the filter array if
// enable, because all the filter extension will not be present in the path found.

// enable sub directories scan
// if "true", the scan process all the subdirectory
// if "false" the scan on scan files in the specified path

// enable Files Scanning
// if "true", the scan process the files
// if "false" the scan do not check files,

// enable full details
// if "false", the only information are filename and size
// if "true", the information are filename, size, dates, perms, type, basename.

// run the Directory scanning
// each new scan will flush the TabFiles properties, to have only the result of the scan

// run the scan

// display some result
echo "<br>Total byte : " .$Dir->FileSize;
"<br>Nb Files : " .$Dir->FileCount;
"<br>Nb Dirs : " .$Dir->DirCount;
"<br>List of extension : <br>";

// to see the contains of the list of the extensions files found

// display all the file found during scanning
foreach ($Dir->TabFiles as $f) {
// print_r($f);