Rename multiple images based on their present titles

Hi guys,

I was wondering if it is possible to write a macro that does the following:
IF an image contains the word “ch00”, rename the image to GFP
IF an image contains the word “ch01”, rename the image to RFP
IF an image contains the word “ch02”, rename the image to CFP
etc etc

Does anybody know how to start this up and how you could do this in one macro?


Hi @hristinahristova,

Create two arrays, one with the text you want to find, another one with the replacement text. Pseudocode:

Then loop over all the images (0..nImages-1),
  get the imageTitle in a string, 
  loop over the wanted words
    find the indexOf the text of each of the wanted words 
    if indexOf doesn't return -1
       do a replace followed by a rename 

See the list of built-in functions for details and use the Plugin > Macro Recorder to get your basic steps.

Give it a try and come back if you need more hints.

Hi @hristinahristova

There’s some ambiguity in your question as to where the images are that you need renaming. I’ve drafted a quick example of how you can do it (although obviously not the only way) renaming any open images that match the titles you give.
This uses getTitle to read the image title and indexOf to search for the substring anywhere in the title (more info at the macro reference).

Hope that helps!

Something like this:

inDir=getDirectory(“Choose the input folder”);
outputDir=getDirectory(“And the output folder”);
myList=getFileList(inDir); //an array

for (j = 0 ; j < myList.length ; j++ ){
path=inDir+myList[j]; //path to each file
print("Processing "+FileName);

	NewFileName=replace(FileName, "ch00", "GFP");
		NewFileName=replace(FileName, "ch01", "RFP");
			NewFileName=replace(FileName, "ch02", "CFP");