PHP Classes

File List

Recommend this page to a friend!

      smb4php  >  All threads  >  File List  >  (Un) Subscribe thread alerts  
Subject:File List
Summary:Recursive file list
Messages:1
Author:Cyberdisyan
Date:2009-12-02 10:36:43
 

  1. File List   Reply   Report abuse  
Picture of Cyberdisyan Cyberdisyan - 2009-12-02 10:36:44
Recursive file list

Hi I dont know if it's the best way to do that, but i create a little function that recursively go trought a folder to get all the file.

I did it for syncronisation across several servers that's the reasion i added also the timestamp after the file name (<filename>@@@<timesamp>)

Here is the function :

/**
* recursive_folder()
*
*
* @param mixed $new_path Starting path.
* @param mixed $purl $purl = $smb->parse_url($url);
* @param mixed $smb $smb = new smb;
* @param mixed $fullflist Array of files or folder_exclude
* folder exculded contains folder with space
* @return
*/
function recursive_folder($new_path, $purl, $smb, &$fullflist){
$fliste = $smb->execute ("cd ".$new_path." ; dir ", $purl);
sizeof($fliste);
if (sizeof($fliste)!=0){ // Min 1 file or folder
foreach ($fliste["info"] as $key => $val){
if ($val[1]=='file'){
$fullflist["files"][] = $new_path."\\".$key."@@@".$val["time"];
}else{
// Folder
if (eregi(" ",$new_path."\\".$key)){
$fullflist["folder_exclude"][] = $new_path."\\".$key;
}else{
recursive_folder($new_path."\\".$key, $purl,$smb, &$fullflist);
}
}
}
}
ob_flush();
flush();
return TRUE;
}


Here is an example of usage :
$smb = new smb;
$purl = $smb->parse_url("smb://<user>:<password>@<server>/<share>/");
$fullflist = array();
recursive_folder("MyFolder\MyFolder2", $purl, $smb, &$fullflist);

// Result :
print_r($fullflist);


This works fine.
1) But when a folder is empty the script stop because of E_USER_ERROR (change it for E_USER_WARNING)
2) I have no idea how to go trough folder with space in it (windows client) Any Idea would be appreciate :)