Recursive path and counting

Hello,
[size=8pt]first sorry for my bad English,[/size] I found an example of tree view a list of all files with jQuery at http://ludo.cubicphuse.nl/jquery-treetable/, unfortunately there is a html list of imaginary files and folders, so I wanted to create a PHP code that I can find out all files, folders and subfolders with files, and then place them to the table. My script works, but I have a problem to use it, because it have to schedule the numbers in attributes data-tt-id and data-tt-parent-id to format, like they are in this example:

Acknowledgements.rtf File 480.95 KB CHUD Folder -- amber Folder -- AmberTraceFormats.pdf File 124.46 KB BigTop Folder -- BigTopUserGuide.pdf File 1314.71 KB Saturn Folder -- SaturnUserGuide.pdf File 694.29 KB Shark Folder -- SharkUserGuide.pdf File 12902.51 KB simg4 Folder -- simg4_plus Folder -- simg5 Folder -- DocSets Folder -- com.apple.Reference_Library.docset Folder -- Contents Folder -- Info.plist File 1.23 KB Resources Folder --

The script, which finds all the (sub)files and (sub)directories:
[php]function directoryToArray($directory, $recursive = true, $listDirs = false, $listFiles = true, $exclude = ‘’) {
$arrayItems = array();
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match("/(^(([.]){1,2})$|(.(svn|git|md))|(Thumbs.db|.DS_STORE))$/iu", $file, $skip);
if($exclude){
preg_match($exclude, $file, $skipByExclude);
}
if (!$skip && !$skipByExclude) {
if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
if($recursive) {
$arrayItems = array_merge($arrayItems, (array)($directory . DIRECTORY_SEPARATOR . $file));
$arrayItems = array_merge($arrayItems, directoryToArray($directory. DIRECTORY_SEPARATOR . $file, $recursive, $listDirs, $listFiles, $exclude));
}
if($listDirs){
$file = $directory . DIRECTORY_SEPARATOR . $file;
$arrayItems[] = $file;
}
} else {
if($listFiles){
$file = $directory . DIRECTORY_SEPARATOR . $file;
$arrayItems[] = $file;
}
}
}
}
closedir($handle);
}
return $arrayItems;
}[/php]

However, I’ve tried it in different ways, but I do not have those numbers in right order to displayed them correctly… If can someone help me, I would be grateful to him…

Sponsor our Newsletter | Privacy Policy | Terms of Service