How to extract base and directory name from a string using ImageJ Macro

imagej
fiji
macro
Tags: #<Tag:0x00007fd53f6d6408> #<Tag:0x00007fd53f6d62c8> #<Tag:0x00007fd53f6d6188>

#1

I have the following sequence:

/Users/pdubois/Desktop/myimage_raw.jpg

Using ImageJ macro (programming language)
how can I extract the base name without extension:

myimage_raw

and directory name full path:

/Users/pdubois/Desktop/


#2

Dear,

all you need is a thorough look at the macro functions:
https://imagej.nih.gov/ij/developer/macro/functions.html

File.getName(path);
“Returns the last name in path’s name sequence.”

File.getParent(path):
“Returns the parent of the file specified by path.”

lastIndexOf(string, substring);
“Returns the index within string of the rightmost occurrence of substring.”

substring(string, index1, index2);
“Returns a new string that is a substring of string. The substring begins at index1 and extends to the character at (index2 - 1).”

// A possible approach:

path = “/Users/pdubois/Desktop/myimage_raw.jpg”;
dir = File.getParent(path) + “/”;
name = File.getName(path);
name = substring(name, 0, lastIndexOf(name, “.”));
print(dir);
print(name);

However, there are other ways to perform the task.

HTH

Herbie