List files in a directory
Hi to all, How can i list the files contained in a directory ? I would like to use it with selecttag to associate a file with a record. The files are very big, uploaded using FTP, so no web-based uploading ! Just listing of a directory in an array. Thanx. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: List files in a directory
you can also look in the http://api.cakephp.org/ at the Folder classyou might find that Folder::ls would be helpfulSam DOn 5/3/06, RosSoft [EMAIL PROTECTED] wrote: check this?php$dirname=ROOT .DS.'vendors' . DS;$dh= opendir($dirname);$files=array();while (false !== ($entry= readdir($dh))){if ( $entry!= '..' $entry!= '.') { $files[]=$entry;}}print_r($files);? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: List files in a directory
Thank you... I modified your script like this: ?php $dirname=ROOT .DS. 'vendors' . DS; $dh= opendir($dirname); $files=array(); while (false !== ($entry= readdir($dh))) { if ( $entry!= '..' $entry!= '.') { $files[$entry]=$entry; } } print_r($files); ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: List files in a directory
I can't understand how to use the Folder class... Can you tell me how to use it or a place where it is explained ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: List files in a directory
So at the top of the controller you could douses('folder','file'); // loads the classes for Folder and Filethen in the controller to get an array of readable folders in a path you could do$path = WWW_ROOT.DS.'dev'.DS.'birdlists'.DS.$filename; $folder = new Folder($path);$ls = $folder-ls();foreach ($ls[1] as $filename) { $file = new File ($path.DS.$filename); if ($file-readable()) { $listForDisplay[$filename] = $path.DS.$filename; }}On 5/3/06, Atkati [EMAIL PROTECTED] wrote: I can't understand how to use the Folder class...Can you tell me how to use it or a place where it is explained ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: List files in a directory
Atkati, You'll find that avoiding Cake methods variables means you write longer files ;) To repeat what Sam D has already written using your own variable names etc. Your script would look something like this: uses('Folder'); $folder = new Folder (VENDORS); $files = $folder-ls(); pr ($files[1]); //Reterns a 2D array, 0 is Dirs 1 is files. Should you need a recursive listing, $folder-findRecursive() is pretty useful. Points of reference: http://api.cakephp.org/class_folder.html#1e48cd2cad566f031f81aca2854b7514 http://www.cakephp.org/search/index/folder Cheers, AD7six --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---