Stepped number and Quick mass rename?
Posted: 24 Jun 2013 13:43
There are two or three excellent number rename scripts in this forum
but I have not been able to find a stepped rename so wrote this.
The idea behind this script was that I scan books and then I am able
to pass on those books. So two pages are scanned and the book doesn't
necessarily start at page 1. Stepped numbering then becomes useful.
shadi.lahham inspired my List/text direct section
see http://www.xyplorer.com/xyfc/viewtopic. ... ren#p88090
Filenames can be edited direct or a list can be copied and pasted in
(after selecting all).
Finally I must give full credit to serendipity for the method of collection.
see http://www.xyplorer.com/xyfc/viewtopic. ... +and+paste
Tested on 1000 files in XP and Win 7 64bit
Totmad1 (totally mad one)
but I have not been able to find a stepped rename so wrote this.
The idea behind this script was that I scan books and then I am able
to pass on those books. So two pages are scanned and the book doesn't
necessarily start at page 1. Stepped numbering then becomes useful.
shadi.lahham inspired my List/text direct section
see http://www.xyplorer.com/xyfc/viewtopic. ... ren#p88090
Filenames can be edited direct or a list can be copied and pasted in
(after selecting all).
Finally I must give full credit to serendipity for the method of collection.
see http://www.xyplorer.com/xyfc/viewtopic. ... +and+paste
Code: Select all
// sections 1,2 and 4 by serendipity see http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=2878&hilit=collect+and+paste
"1 Collect items : collect"
$base = self ("base");
$Items = getkey ( "items", "collected", "$base.ini");
$Count = getkey ( "count", "collected", "$base.ini");
focus;
$SelectedItemsPath= getinfo ("SelectedItemsPathNames", "|")."|";
$CountSelectedItems= getinfo ("CountSelected");
set $Items, $SelectedItemsPath.$Items;
incr $Count, $Count, $CountSelectedItems;
setkey $Items, "items", "collected", "$base.ini";
setkey $Count, "count", "collected", "$base.ini";
status "Items collected=$CountSelectedItems (Total=$Count)", BF0000, progress;
focus c;
"2 Edit/Show collected items : show"
$base = self ("base");
$Items = getkey ( "items", "collected", "$base.ini");
$Count = getkey ( "count", "collected", "$base.ini");
$ForTextMessage = replace ( $Items, "|",<crlf>);
incr $Count, $Count,0;
$Response = input("You have collected $Count items (you can add/remove items)", , $ForTextMessage,m, );
// Update $Items
$Items = replace ( $Response, "<crlf>", "|");
// Update $Count
$Tokens = regexreplace ( $Items, "[^|]");
$Count = strlen ( $Tokens);
setkey $Items, "items", "collected", "$base.ini";
setkey $Count, "count", "collected", "$base.ini";
////////////////////////// above code by serendipity //////////////////////////////////////////////////////////
-
"3 = numbering"
global $z , $n;
$base = self ("base");
$psb = input ("(p)refix , (s)uffix (default) or (b)oth ?",,"s");
$start =input("No. to start at",,1);
$step=input("No. to step",,1);
$sep=input("insert seperater(no illegal)",,"_");
$zero=input("zero's (Y)es (default) or (N)o ?",,"y");
$collection = getkey ( "items", "Collected", "$base.ini");
$Count = getkey ( "count", "Collected", "$base.ini");
$i = 1; $list = $start;
while ($i < $Count) {
$start = $start + $step;
$list = $list .| $start;
$i++;
}
$i = 1; $newfile="";
while ($i < $Count+1) {
$file=gettoken($collection,$i,"|");
$z= gettoken($list,$i,"|"); // numbers
$q = getpathcomponent( "$file", "base");
$ext= getpathcomponent( "$file", "ext");
if ($z < 10) {
$n= "000";
}
elseif ( $z < 100) {
$n= "00";
}
elseif ( $z < 1000) {
$n= "0";
}
else {
$n= "";
}
if ($Count < 100 ) {
sub _LessThan100;
}
if ($Count > 99 AND $Count < 1000 ) {
sub _LessThanThou;
}
if ( ($psb == "p") AND ($zero == "n" OR $zero == "N") ) {
$file=$z.$sep.$q .".$ext" . "|";
}
elseif ( $psb == "b" AND $zero == "n" OR $zero == "N" ) {
$file=$z.$sep.$q .$sep.$z.".$ext" . "|";
}
elseif ( $psb == "p" AND $zero == "y" OR $zero == "Y" ) {
$file=$n.$z.$sep.$q .".$ext" . "|";
}
elseif ( $psb == "b" AND $zero == "y" OR $zero == "Y" ) {
$file=$n.$z.$sep.$q .$sep.$n.$z.".$ext" . "|";
}
elseif ( $zero == "n" OR $zero == "N") {
$file=$q .$sep.$z.".$ext" . "|";
}
else {
$file=$q .$sep.$n.$z.".$ext" . "|";
}
$file = replace ( $file, " ","" ) ;
$newfile=$newfile . $file;
$i++;
}
$newfile = replace ( $newfile, "|", <crlf> ) ;
$newfile = input("You have collected $Count items (you can add/remove items)", , $newfile,m);
$newfile = replace ( $newfile, <crlf>, "|" ) ;
setkey $newfile, "Newfile_Names", "Collected", "$base.ini";
$Count = getkey ( "count", "Collected", "$base.ini");
$i = 1;
while ($i < $Count+1) {
$file=gettoken($collection,$i,"|");
$file2=gettoken($newfile,$i,"|");
rename , "$file2 /e", , "$file";
$i++;
}
"_LessThan100"
global $z , $n;
if ($z < 10) {
$n= "0";
}
elseif ($z > 9) {
$n= "";
}
"_LessThanThou"
global $z , $n;
if ($z < 10 ) {
$n= "00";
}
elseif ( $z > 9 AND $z < 100) {
$n= "0";
}
else {
$n= "";
}
" msg To use numbering after. you need to run [4 Empty collected items] and then recollect before numbering" ;
"3 = List/text direct (no numbering included)"
// could easily made to have choice to edit extensions
$base = self ("base");
$collection = getkey ( "items", "Collected", "$base.ini");
$Count = getkey ( "count", "Collected", "$base.ini");
$i = 1; $newfile="";
while ($i < $Count+1) {
$file=gettoken($collection,$i,"|");
$q = getpathcomponent( "$file", "base");
$ext= getpathcomponent( "$file", "ext");
// $file=$q .".$ext" . <crlf>; // for editing ext
$file=$q . <crlf>;
$file = replace ( $file, " ","" ) ; // to removes spaces
$newfile=$newfile . $file;
$i++;
}
$newfile = input ("Editing: " . ( "You have - $Count - items""Newfile_Names"""),, $newfile, m );
$newfile = replace ( $newfile, <crlf>, "|" ) ;
setkey $newfile, "Newfile_Names", "Collected", "$base.ini";
$i = 1;
while ($i < $Count+1) {
$file=gettoken($collection,$i,"|");
$file2=gettoken($newfile,$i,"|");
//rename , "$file2 /e", , "$file"; // for editing ext
rename , "$file2 ", , "$file";
$i++;
}
- // code below written by serendipity
"4 Empty collected items : empty"
$base = self ("base");
setkey 1, "exists", "tmp", "$base.ini";
$path = self ("path");
delete 0, 0, "$path\$base.ini";
status "Collected items emptied", , alert;
focus c;
-
"Edit script : edit"
$ScriptFile= self ("file");
// run "$p_note" $ScriptFile,w; // used on xp
run $p_note $ScriptFile,w;
-
"CANCEL"
Totmad1 (totally mad one)









