PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/unlink.php

https://bitbucket.org/chregu/tmcli
PHP | 65 lines | 52 code | 11 blank | 2 comment | 14 complexity | bdd367c492c82dffbe08bc4247b2028c MD5 | raw file
  1. <?php
  2. include_once("settings.php");
  3. $bkdir = $outdir.$bkdir.".inProgress";
  4. if (!isset($argv[1])) {
  5. die("please specify the directory to delete\n");
  6. }
  7. $bkdir = $argv[1];
  8. parseDir($bkdir."/");
  9. DELETE_RECURSIVE_DIRS($bkdir);
  10. function parseDir($dir,$level = 0) {
  11. global $maxdir;
  12. foreach (new DirectoryIterator($dir) as $fileInfo) {
  13. if($fileInfo->isDot()) {
  14. continue;
  15. }
  16. if ($fileInfo->isDir()) {
  17. $oripath = $dir.$fileInfo->getFilename();
  18. if ($level < 2) {
  19. print $oripath."\n";
  20. }
  21. @unlink($oripath);
  22. if (file_exists($oripath)) {
  23. if ($level < $maxdir + 2) {
  24. parseDir($oripath."/",$level+ 1);
  25. } else {
  26. // print $oripath ." UNLINKED\n";
  27. }
  28. }
  29. }
  30. }
  31. }
  32. function DELETE_RECURSIVE_DIRS($dirname,$level = 0)
  33. { // recursive function to delete
  34. // all subdirectories and contents:
  35. if(is_dir($dirname))$dir_handle=opendir($dirname);
  36. while(false !== $file=readdir($dir_handle))
  37. {
  38. if($file!="." && $file!="..")
  39. {
  40. if(!is_dir($dirname."/".$file) || is_link($dirname."/".$file)) {
  41. unlink ($dirname."/".$file);
  42. }
  43. else {
  44. if ($level < 2) {
  45. print $dirname."/".$file."\n";
  46. }
  47. DELETE_RECURSIVE_DIRS($dirname."/".$file,$level + 1);
  48. }
  49. }
  50. }
  51. closedir($dir_handle);
  52. rmdir($dirname);
  53. return true;
  54. }