소스 검색

add new settings and limit initial dir&file listing to preview size

Christopher 5 년 전
부모
커밋
85d2c7418c
1개의 변경된 파일45개의 추가작업 그리고 10개의 파일을 삭제
  1. 45 10
      mass-rename.php

+ 45 - 10
mass-rename.php

@@ -18,11 +18,22 @@
 //	not of significant concern.
 $remove_self = false;
 
+//	If true, the script will show a preview of all discovered files and dir-
+//	ectories. See the setting "$max_preview_size" for maximum preview results.
+$enable_dir_scan_preview = true;
+
+//	If true, the script will spew the full command immediately prior to its
+//	execution during the final renaming process.
+$display_full_cmd = true;
+
+//	If true, the script will spew the progress during the rename operation.
+$display_progress = true;
+
 //	If true, directories will be skipped and thus will not be renamed.
 $skip_directories = true;
 
-//	Maximum results per preview group.
-$count_group_size = 100;
+//	Maximum results per preview.
+$max_preview_size = 100;
 
 
 
@@ -160,6 +171,8 @@ else{
 	exit(1);
 }
 
+echo " > Performing initial directory traversal, please wait...\n";
+
 $contents = array();
 GET_DIR_CONTENTS($dirToTraverse, $contents);
 
@@ -174,13 +187,32 @@ if ($remove_self){
 
 // var_dump($contents);
 
-echo " > FILE AND DIRECTORY LIST:\n ================================\n";
-foreach ($contents as $c){
-	
-	echo "   " . $c . "\n";
-}
+echo " > Initial directory traversal complete.\n";
+
+$counter = 0;
+$stop_preview = false;
+
+if ($enable_dir_scan_preview){
+
+	echo " > ORIGINAL FILE AND DIRECTORY PREVIEW:\n ================================\n";
+	foreach ($contents as $c){
+		
+		if ($stop_preview)
+			break;
+		$counter++;
+		
+		if ($counter > $max_preview_size){
+			
+			echo " --------- (results truncated)\n";
+			$stop_preview = true;
+			break;
+		}
+		
+		echo "   " . $c . "\n";
+	}
 
-echo " ================================\n";
+	echo " ================================\n";
+}
 
 $content_map = array();
 $content_map_new = array();
@@ -226,7 +258,7 @@ foreach ($content_map as $p => $f){
 		
 		$counter++;
 		
-		if ($counter > $count_group_size){
+		if ($counter > $max_preview_size){
 			
 			echo " --------- (results truncated)\n";
 			$stop_preview = true;
@@ -267,7 +299,10 @@ if (ARE_STRINGS_EQUAL($begin_operation, "Y", true)){
 			
 			$new_path = dirname($p) . "/" . $content_map_new[$p];
 			$cmd = "mv \"" . $p . "\" \"" . $new_path . "\"";
-			echo " >>> " . $cmd . "\n";
+			
+			if ($display_full_cmd)
+				echo " >>> " . $cmd . "\n";
+			
 			exec($cmd);
 		}