Naming file (cut file extension from name)

Tags: #<Tag:0x00007fb882f5ba80>


roiManager(“Select”, 0);
roiname = Dialog.getString();
name = getInfo(“slice.label”);
roiname2 = roiname + “_” + name;
run(“Duplicate…”, " ");
saveAs(“jpeg”, dir+roiname2);

Hii ,
So in upper code ROI name has extension .roi at the end and I would like to romove this extension.

So is it possible that when macro gets ROI name as a string i can limit string in a way that it will start from 5th letter from the end.

for example roi name B4.roi should be just B4.



Of course, you can use the built-in macro functions indexOf and substring. Have a look at this example:

name = "my-file-name.roi";
dotIndex = indexOf( name, "." );
nameWithoutExtension = substring( name, 0, dotIndex );
print( "Name without extension: " + nameWithoutExtension );


Quick&dirty alternative:

name = replace(name, “.roi”, “”)