Class to list/remove recursively files into a directory


/ Published in: PHP
Save to your folder(s)

Class to list/remove recursively files into a directory


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /*
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17.  
  18.  
  19. /*
  20. Criado por Gabriel Francisco frc.gabriel[at]gmail.com
  21.  
  22. $dir_path = caminho do diretorio que contem arquivos temporarios, cache ou qualquer coisa a ser removido
  23. */
  24. class LimpaCache {
  25.  
  26. private $dir_path;
  27.  
  28. public function setDir($dir) {
  29. $this->dir_path = $dir;
  30. }
  31.  
  32. public function listar() {
  33. if ($handle = opendir($this->dir_path)) {
  34. while (false !== ($entry = readdir($handle))) {
  35. echo "$entry\n</br>";
  36. }
  37. closedir($handle);
  38. }
  39. }
  40.  
  41. public function limpar() {
  42. if ($handle = opendir($this->dir_path)) {
  43. while (false !== ($entry = readdir($handle))) {
  44. if (!is_dir($entry))
  45. unlink($this->dir_path . '/' . $entry);
  46. }
  47. closedir($handle);
  48. }
  49. }
  50. }
  51.  
  52. //$limpa = new LimpaCache;
  53. //$limpa->setDir('/tmp/teste');
  54. //$limpa->listar();
  55. //$limpa->limpar();
  56. ?>

URL: https://gist.github.com/1452877

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.