Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Script to recursively remove all traces of svn from a directory tree
  4.  * Author: Ryan Bales, Creative Anvil 2011
  5.  */
  6. ini_set('memory_limit','512M');
  7.  
  8. function usage()
  9. {
  10.         ob_start(); ?>
  11.  
  12.                         ::UnSvn::
  13. Script to recursively remove all traces of svn from a directory tree
  14.  
  15. Usage: /path/to/php unsvn.php /path/to/directory
  16. <?php echo ob_get_clean();
  17. }
  18. function rrmdir($dir) {
  19.    if (is_dir($dir)) {
  20.      $objects = scandir($dir);
  21.      foreach ($objects as $object) {
  22.        if ($object != "." && $object != "..") {
  23.          if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
  24.        }
  25.      }
  26.      reset($objects);
  27.      rmdir($dir);
  28.    }
  29. }
  30. function unsvn($files)
  31. {
  32.         foreach( $files as $file ) {
  33.                 $filename = str_replace(dirname($file),'',$file);
  34.                 if( $filename == '/.' || $filename == '/..' ) {
  35.                         continue;
  36.                 } elseif ( $filename == '/.svn' && is_dir($file) ) {
  37.                         echo "deleting file {$file}\n";
  38.                         rrmdir($file);
  39.                 } else {
  40.                         if( is_dir($file) ) {
  41.                                 // recurse
  42.                                 $inner_files = scandir($file);
  43.                                 $dirname = $file;
  44.                                 $filepaths = array();
  45.                                 foreach( $inner_files as $inner_file ) {
  46.                                         $filepaths[] = "{$dirname}/{$inner_file}";
  47.                                 }
  48.                                 unsvn($filepaths);             
  49.                         }
  50.                 }              
  51.         }
  52. }
  53.  
  54.  
  55. if( count($argv) > 1 ) {
  56.         if( is_dir($argv[1]) ) {
  57.                 unsvn(array($argv[1]));
  58.         } else {
  59.                 usage();
  60.         }
  61. } else {
  62.         usage();
  63. }