列出文件夹中的所有文件时,我不想显示任何.db文件。
这是我的代码:
$ticketId = 100;
$uploadPath = Configure::read('Config.uploadPath').'/support_tickets/';
$dir = new Folder($uploadPath.$ticketId);
$fileList = $dir->read(true, array('*.db'));
现在$ fileList存储所有文件。
如何正确撰写声明?
答案 0 :(得分:0)
我会尝试$ files = $ dir-> find('。*。db',false);
答案 1 :(得分:0)
Iterators非常适合此类事情。这是SVG文件的基本文件
/**
* @brief SvgIterator for finding svg files
*/
class SvgIterator extends FilterIterator {
public function accept() {
$isSvg = $this->current()->getExtension() == 'svg';
if(!$isSvg) {
return false;
}
return $this->_getData();
}
/**
* @brief method for getting data from the SVG files
*
* @return boolean
*/
protected function _getData() {
$this->current()->_aspectRatio = SvgConvert::aspectRatio($this->current()->getPathname());
return true;
}
/**
* @brief calculate the aspect ratio of the curret file
*
* @return float
*/
public function aspectRatio() {
return $this->current()->_aspectRatio;
}
}
用法:
$it = new SvgIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path)));
$return = array();
for ($it->rewind(); $it->valid(); $it->next()) {
$file = array(
'file' => $it->current()->getFilename(),
'aspect_ratio' => $it->aspectRatio()
);
$return[] = $file;
}