Page 1 of 1

Various Rename Jobs

Posted: 03 Apr 2008 13:01
by jacky
Here's a few scripts working together, and indeed inspired by TheQwerty previous files, though I haven't used his scripts cause it was still using the old syntax by then, so I just did some similar functions on my own.

Rename.xys

Code: Select all

"&1 - Remove/Convert common IE number suffix..."
	load "Rename - IE";
"&2 - Removing characters from filename..."
	load "Rename - Remove";
-
"&3 - Insert text..."
	load "Rename - Insert";
-
"&4 - Search and Replace..."
	copytext "";
	sub _sr;
"&5 - Search and Replace... - Preview"
	copytext "p";
	sub _sr;
-
"Cancel"

"_sr"
	set $prev, <clipboard>;
	input $s, "Enter the text to search for";
	input $r, "Enter the text to replace ""$s"" with";
	rename sr, "$s/$r", $prev;

Rename - Remove.xys

Code: Select all

"&1 - Remove n first characters from filename"
	copytext "";
	sub _removeLeft;
"&2 - Remove n first characters from filename - Preview"
	copytext "p";
	sub _removeLeft;
-
"&3 - Remove n last characters from filename"
	copytext "";
	sub _removeRight;
"&4 - Remove n last characters from filename - Preview"
	copytext "p";
	sub _removeRight;
-
"&5 - Remove characters"
	copytext "";
	sub _removeChars;
"&6 - Remove characters - Preview"
	copytext "p";
	sub _removeChars;
-
"&Back..."
	load "Rename";
"Cancel"

"_removeLeft"
	set $prev, <clipboard>;
	input $n, "Number of characters to remove from left of filename :";
	rename re, "(?#Remove $n first chars)^(?:^.{$n}(.+\.[^\.]+))|(?:^[^\.]{$n}([^\.]+))$>$1$2", $prev;
"_removeRight"
	set $prev, <clipboard>;
	input $n, "Number of characters to remove from right of filename :";
	rename re, "(?#Remove $n last chars)^(?:([^\.]+)[^\.]{$n}$)|^(?:(.+).{$n}(\.[^\.]+)$)>$1$2$3", $prev;
"_removeChars"
	set $prev, <clipboard>;
	input $c, "Enter the characters to be stripped from the filename";
	rename sr, "$c", $prev;
Rename - Insert.xys

Code: Select all

"&1 - Insert prefix"
	copytext "";
	sub _insertPrefix;
"&2 - Insert prefix - Preview"
	copytext "p";
	sub _insertPrefix;
-
"&3 - Insert text at postion n"
	copytext "";
	sub _insertText;
"&4 - Insert text at postion n - Preview"
	copytext "p";
	sub _insertText;
-
"&5 - Insert suffix"
	copytext "";
	sub _insertSuffix;
"&6 - Insert suffix - Preview"
	copytext "p";
	sub _insertSuffix;
-
"&Back..."
	load "Rename";
"Cancel"

"_insertPrefix"
	set $prev, <clipboard>;
	input $t, "Enter the text to insert on the left of the filename";
	rename re, "(?#Insert prefix)^(.+)$>$t$1", $prev;
"_insertSuffix"
	set $prev, <clipboard>;
	input $t, "Enter the text to insert on the right of the filename";
	rename re, "(?#Insert suffix)^(.+?)(|\.[^\.]+)$>$1$t$2", $prev;
"_insertText"
	set $prev, <clipboard>;
	input $p, "Enter the position to insert the text at (after n character, so 0 means prefix)";
	input $t, "Enter the text to insert at position $p";
	rename re, "(?#Insert test at postion $p)^(?:([^\.]{$p})(.*))|(?:(.{$p})(.*\.[^\.]+))$>$1$3$t$4$2", $prev;

Rename - IE.xys

Code: Select all

"&1 - Remove common IE suffix ''[X]''"
	copytext "";
	sub _remove;
"&2 - Remove common IE suffix ''[X]'' - Preview"
	copytext "p";
	sub _remove;
-
"&3 - Convert common IE suffix ''[X]''"
	copytext "";
	sub _convert;
"&4 - Convert common IE suffix ''[X]'' - Preview"
	copytext "p";
	sub _convert;
-
"&Back..."
	load "Rename";
"Cancel"

"_remove"
	rename re, "(?#Remove common IE suffix)^(.+)\[[0-9]+\](\..+)$>$1$2", <clipboard>;
"_convert"
	set $prev, <clipboard>;
	input $p, "What prefix should come before the number - eg. "" (""", " - ";
	input $s, "What suffix should come after the number - eg. "")""", "";
	rename re, "(?#Convert common IE suffix)^(.+)\[([0-9]+)\](\..+)$>$1$p$2$s$3", $prev;

Posted: 04 Apr 2008 08:18
by zridling
Thanks Jacky, these are great!