SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. set_time_limit(0);
  3. function process_folder($path, $destination_path = null) {
  4.     $files = array_diff(scandir($path), array('..', '.'));
  5.     foreach($files as $file) {
  6.             $ext = pathinfo($file, PATHINFO_EXTENSION);
  7.             if($ext == "url") { unlink($path."/".$file); }
  8.     }
  9.     if($destination_path) {
  10.         $files = array_diff(scandir($path), array('..', '.'));
  11.         foreach($files as $file) {
  12.             echo "\tMoviendo ".$file." a ".$destination_path."\n";
  13.             rename($path."/".$file, $destination_path."/".$file);
  14.         }
  15.     }
  16.     $files_remaining = array_diff(scandir($path), array('..', '.'));
  17.     if(!sizeof($files_remaining)) {
  18.         rmdir($path);
  19.     }
  20. }
  21.  
  22. $parent_folder = $argv[1] ? $argv[1] : '/media/series2/descargas/completados';
  23. $destination_folder = '/media/series1';
  24.  
  25. $parent_folders = array_diff(scandir($parent_folder), array('..', '.'));
  26. foreach($parent_folders as $each_folder) {
  27.     $series_name = trim(current(explode("-", $each_folder)));
  28.     $series_name = trim(preg_replace("/\([^)]+\)/","",$series_name));
  29.     $series_name = current(preg_grep("/$series_name$/i", glob($destination_folder."/*")));
  30.     if(!$series_name) {
  31.         echo "No hay carpeta creada, o se trata de una PelĂ­cula: ".basename($each_folder)."\n";
  32.         process_folder($parent_folder."/".$each_folder);
  33.     }
  34.     else
  35.     {
  36.         echo "Procesando carpeta de: ".basename($series_name)."\n";
  37.         process_folder($parent_folder."/".$each_folder, $series_name);
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top