Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- function process_folder($path, $destination_path = null) {
- $files = array_diff(scandir($path), array('..', '.'));
- foreach($files as $file) {
- $ext = pathinfo($file, PATHINFO_EXTENSION);
- if($ext == "url") { unlink($path."/".$file); }
- }
- if($destination_path) {
- $files = array_diff(scandir($path), array('..', '.'));
- foreach($files as $file) {
- echo "\tMoviendo ".$file." a ".$destination_path."\n";
- rename($path."/".$file, $destination_path."/".$file);
- }
- }
- $files_remaining = array_diff(scandir($path), array('..', '.'));
- if(!sizeof($files_remaining)) {
- rmdir($path);
- }
- }
- $parent_folder = $argv[1] ? $argv[1] : '/media/series2/descargas/completados';
- $destination_folder = '/media/series1';
- $parent_folders = array_diff(scandir($parent_folder), array('..', '.'));
- foreach($parent_folders as $each_folder) {
- $series_name = trim(current(explode("-", $each_folder)));
- $series_name = trim(preg_replace("/\([^)]+\)/","",$series_name));
- $series_name = current(preg_grep("/$series_name$/i", glob($destination_folder."/*")));
- if(!$series_name) {
- echo "No hay carpeta creada, o se trata de una Película: ".basename($each_folder)."\n";
- process_folder($parent_folder."/".$each_folder);
- }
- else
- {
- echo "Procesando carpeta de: ".basename($series_name)."\n";
- process_folder($parent_folder."/".$each_folder, $series_name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement