About

This ARexx script will rename selected files sequentially in Directory Opus 4 based on an input file-name prefix and sequential pattern template whilst retaining the original file-name extensions as they are.

In other words, it satisfies a necessity to be able to sequentially rename files: for example, suppose that you have the following files in a window pane:

  • meinthepark.jpg
  • meathome.jpg
  • meupyournostrills.jpg

and that you wish to rename the files sequentially to obtain:

  • Photo_01.jpg
  • Photo_02.jpg
  • Photo_03.jpg

in that case, this script will do it for you.

When the script runs from Directory Opus, it will ask you for two parameters:

  • a file-name prefix - following the example above, you would enter Photo_
  • a rename pattern - following the example above, you would enter 01

The sequential rename is alpha-numerical where the range 0..9 represents one numeric rotation and a..z represents one alphabetic rotation. This is performed with carry, such that if the rename pattern would have been specified as 0y8, then the following sequence would be achieved:

  • 0y8
  • 0y9
  • 0z0
  • 0z1
  • 0z2
  • 0z3
  • 0z4
  • 0z5
  • 0z6
  • 0z7
  • 0z8
  • 0z9
  • 1a0
  • 1a1

In other words, this would allow you to rename files like:

  • Photo_aaa.jpg
  • Photo_aab.jpg
  • Photo_aac.jpg

as well as mixing-in numbers and letters in the sequence.

Download

How to Install

  1. Extract the archive
  2. Place DOpus4-SeqRename.rexx wherever you see fit (it is tidy, for example, to create an ARexx directory in DOPUS4: and then place your scripts there).
  3. Open DirectoryOpus4 and right-click and go to Project→Configure
  4. On the screen that pops-up, go to Buttons and create a new button somewhere where you see fit.
    1. Give the button a name (SeqRename, for example) and create a new entry.
    2. Set the cycler to ARexx and click the magnifying glass to enter the path to the DOpus4-SeqRename.rexx script.
  5. You do not need to set any flags.
  6. Save and exit and you are done.

How To Use

Select some files and press the SeqRename button. You will be prompted for a file-name prefix and a pattern. After those parameters are supplied to the ARexx script, the script will rename all your files sequentially.

Developer Notes

The script uses a custom-implementation of some functions which can all be found on the ARexx FUSS page.

Code

DOpus4-SeqRename.rexx
/*
 *  $VER: DOpus4-SeqRename 1.0 (07 Jul 2015) by Wizardry and Steamworks
 *
 *      © 2015 Wizardry and Steamworks
 *
 *  PROGRAMNAME:
 *      DOpus4-SeqRename
 *
 *  FUNCTION:
 *      Batch-renames files given a prefix and an increment pattern.
 *
 *  USAGE:
 *      ARexx command DOpus4-SeqRename.rexx (from DOpus)
 *
 *  $HISTORY:
 *
 *  07 Jul 2015 : 1.0 : initial release
 *
 */
 
Opus = Address()    /* Get the DOpus address. */
Options RESULTS     /* Request results. */
Address value Opus  /* Use the DOpus address. */
 
Busy On             /* Set the busy pointer. */
 
/* Get all the selected items and check if something is actually selected. */
GetSelectedAll '*'  /* Get all the selected items. */
ThisItems = RESULT
 
/* Normalize, heh... */
ThisItems = Translate(Translate(ThisItems, '/', ' '), ' ', '*')
 
n = Words(ThisItems)                            /* Get the number of selected items. */
If n <= 0 Then                              /* Check if no items were selected. */
    Do                                      /* If no items were selected, */
        TopText 'No items were selected...'
        Busy Off                            /* turn off the busy pointer. */
        Exit                                /* and terminate. */
    End
 
TopText 'Please enter the rename file-name prefix.'
GetString "Prefix:"
Prefix = RESULT
If Prefix = 'RESULT' Then
    Do
        TopText 'No rename file-name prefix provided!'
        Busy Off
        Exit
    End
 
TopText 'Please enter the rename pattern suffix.'
GetString "Pattern:"
Pattern = RESULT
If Pattern = 'RESULT' Then
    Do
        TopText 'No rename pattern suffix provided!'
        Busy Off
        Exit
    End
 
/* Generate all the intermediary patterns. */
Sequence = wasGenerateStringSequence(Pattern, Words(ThisItems))
 
/* Get all items. */
GetAll '*' ThisWindow
AllItems = RESULT
 
/* Normalize, heh... */
AllItems = Translate(Translate(AllItems, '/', ' '), ' ', '*')
 
/* Batch rename all the items... */
TopText "Sequence-renaming all selected items..."
SequenceIndex = 1
Count = Words(AllItems)
Do i = 1 To Count
    ThisName = SubWord(AllItems, i, 1)
 
    /* If the file is not selected, then skip it. */
    If Find(ThisItems, ThisName) = 0 Then Iterate i
 
    OrigName = Translate(ThisName, ' ', '/')
 
    /* Preserve file-name extension during rename. */
    Dot = LastPos('.', OrigName)
    Select
        When Dot ~= 0 Then /* We have a file extension. */
            Rename OrigName Prefix||SubWord(Sequence, SequenceIndex, 1)||SubStr(OrigName, Dot)
        Otherwise
            Rename OrigName Prefix||SubWord(Sequence, SequenceIndex, 1)
    End
 
    /* Bail if the sequence rename fails. */
    If RC ~= 0 Then
        Do
            Notify "There was an error renaming: "OrigName
            BusyOff
            Exit
        End
 
    SequenceIndex = SequenceIndex + 1
End
 
TopText "\m/(-.-)\m/ There you go!"
Busy Off    /* Turn off the busy pointer. */
Exit        /* Terminate. */
 
/*************************************************************************/
/*    Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3    */
/*************************************************************************/
wasGenerateStringSequence: procedure /* Generate a string sequence.      */
	Parse ARG First,Count,X
 
	If Count = 0 Then Return ''
 
	If Length(X) ~= 1 Then 
	    Return First||" "||wasGenerateStringSequence(First, Count - 1, 1)
 
	Result = ''
	c = 1
	Length = Length(First)
	Do While Length ~= 0
	    x = SubStr(First, Length, 1)
	    Select
	        When DataType(x) = 'NUM' Then
	            Do
	                Sum = x + c
	                Select
            	        When Sum > 9 Then
            	            Do
            	                Result = 0||Result
            	                c = 1
            	            End
            	        Otherwise
            	            Do
            	                Result = Sum||Result
            	                c = 0
            	            End
            	    End
	            End
	        Otherwise
	            Do
	                Sum = D2C(C2D(x) + c)
	                Select
	                    When Sum > 'z' Then
	                        Do
	                            Result = 'a'||Result
	                            c = 1
	                        End
	                    Otherwise
	                        Do
	                            Result = Sum||Result
	                            c = 0
	                        End
	                End
	            End
	    End
	    Length = Length - 1
	End
 
	If c ~= 0 Then Result = c||Result
 
	If Count - 1 = 0 Then Return Result
 
Return Result||" "||wasGenerateStringSequence(Result, Count - 1, 1)

amiga/directoryopus/4/sequence_rename.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.