add_recurse_folder($dir . $file . '/', $zipdir . $file . '/'); } } else { // Add the files $this->addFile($dir . $file, $zipdir . $file); $filenct +=1; } } //Add the directory when folder was empty if( (!empty($zipdir)) && ($filenct==0)) { // remove directory separator before addEmptyDir // otherwhisen create double folder in zip $this->addEmptyDir(substr($zipdir, 0, -1)); } } } } /** * @brief add file to the current file from a folder matching the pattern $p_pattern * @param $p_folder string folder where are the file to add * @param $p_pattern string pattern syntax preg_match * @return int number of files added * @exception throw an exception err message is ERR-EZ95 if file cannot be added */ function add_file_pattern( $p_folder,$p_pattern):int { if (!is_dir($p_folder)) { throw new \Exception("ERR-ZE87"); } $dir=opendir($p_folder); if( $dir==false) throw new \Exception("ERR-ZE90"); $added=0; while( ($entry=readdir($dir)) != false) { if ( preg_match($p_pattern, $entry)) { if ( ! $this->addFile($p_folder . "/" . $entry,$entry) ) throw new \Exception("ERR-EZ95 : cannot add $p_folder/$entry"); $added++; } } return $added; } }