Parcourir la source

prelim tests all pass

Christopher il y a 5 ans
Parent
commit
3eedcc9ee9
1 fichiers modifiés avec 58 ajouts et 7 suppressions
  1. 58 7
      mass-rename.php

+ 58 - 7
mass-rename.php

@@ -85,6 +85,30 @@ function REPLACE2($str, $search, $replace){
 	return preg_replace($search, $replace, $str);
 }
 
+//	Returns true if both strings are the same. Performs a case-insensitive comparison unless third parameter is true.
+function ARE_STRINGS_EQUAL($str1, $str2, $case_sensitive = false){
+	
+	switch($case_sensitive){
+		case true:
+			if (strcmp($str1, $str2) == 0){
+				return true;
+			}
+			else{
+				return false;
+			}
+			break;
+		default:
+			if (strcasecmp($str1, $str2) == 0){
+				return true;
+			}
+			else{
+				return false;
+			}
+			break;
+	}
+	return false;	
+}
+
 //	======================================================================
 
 if (isset($argv[1])){
@@ -217,17 +241,44 @@ foreach ($content_map as $p => $f){
 }
 
 
-/*
-
 echo " *** Please review above results carefully ***\n\n";
-echo " - To begin operation (cannot be undone), type 'Y' and press ENTER/RETURN.\n";
-echo " - To preview more results, type 'P'  and press ENTER/RETURN.\n";
-echo " - To cancel script without making any changes, type 'N' and press ENTER/RETURN.\n";
-echo "\n >> Begin operation? [Y/N/P]: ";
+echo "  - To begin operation (cannot be undone), type 'Y' and press ENTER/RETURN.\n";
+// echo " - To preview more results, type 'P'  and press ENTER/RETURN.\n";
+echo "  - To cancel script without making any changes, type 'N' and press ENTER/RETURN.\n";
+echo "\n  >> Begin operation? [Y/n]: ";
 $response = fgets(STDIN);
 $begin_operation = substr($response, 0, strlen($response) - 1);
 
-*/
+if (ARE_STRINGS_EQUAL($begin_operation, "Y", true)){
+	
+	echo "\n  > Operation started by user.\n";
+	$countdown_timer = 5;
+	while($countdown_timer > 0){
+		
+		echo "  > Operation starting in " . $countdown_timer . " second(s)...\n";
+		$countdown_timer--;
+		sleep(1);
+	}
+	
+	foreach ($content_map as $p => $f){
+		
+		if (!is_dir($p)){
+			
+			$new_path = dirname($p) . "/" . $content_map_new[$p];
+			$cmd = "mv \"" . $p . "\" \"" . $new_path . "\"";
+			echo " >>> " . $cmd . "\n";
+			exec($cmd);
+		}
+		
+	}	
+	
+	echo "  > Operation complete.\n";
+	exit(0);
+	
+}
+
+echo "\n  > Operation cancelled by user.\n";
+exit(0);