<?php

function rscandir($path) {
  $dirs = scandir($path);
  $count = 0;
  foreach ($dirs as $dir) {
    if ($dir=='.' || $dir=='..') continue;
    $count++;
    $dname = $path.'/'.$dir;
    if (is_dir($dname)) if (rscandir($dname)==0) {
      echo "$dname\n";
      rmdir($dname);
      $count--;
    }
  }
  return $count;
}

rscandir($argv[1]);
