Stepped number and Quick mass rename?

Discuss and share scripts and script files...
Post Reply
totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Stepped number and Quick mass rename?

Post by totmad1 »

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

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"

Tested on 1000 files in XP and Win 7 64bit


Totmad1 (totally mad one)
totmad1 (totally mad one)

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Stepped number and Quick mass rename?

Post by j_c_hallgren »

Hi and welcome to the XY forums!

Just a note about your script: I think it would be helpful to have either some screenshots and/or text examples/descriptions of what inputs/outputs in terms of filenames your script works with.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Re: Stepped number and Quick mass rename?

Post by totmad1 »

Image
This first image shows the menu notice item 2 this should be used to check no. of items collected
and if you want to add/remove any filenames from list (full paths req.)


Image
note that item count should have been checked

Image

Image

Image
this one shows a change to a step of 2

Image

Image

Image
this shows what your files will be renamed to. This is the last point where you can check the quantity
(should have cancelled here. Wrong quantity showing)

Image
finally image of files renumbered

Image
This is what you will see when you use 3 = List/text direct
This shows 1002 files without extensions (those wondering why the quantity difference between
this image and the last, there was one folder.

Which leads me nicely into an apology. After reading j_c_hallgren's note
I suddenly realised that some people have dots in there paths. so I retried with a
folder named .100x2 (real original). I have to report that I had some real interesting results.
One attempted run I was shown 113 items,ran again 113. Tried something different got 273.
Finally had to concede that DOES NOT work with dots in the path (not affected by extra dots in filename).
Finally in answer to what extensions this works with. In all tests extensions haven't any effect.
Interestingly my example folder was treated as an extension.
totmad1 (totally mad one)

Post Reply