ImageJ macro code to change directory

I am learning how to write macros in ImageJ. I have the user select a folder where data is stored, e.g.,

path=getDirectory("Choose a data folder");

Once the user has selected the folder, e.g.,

path = D:\data_superfolder\data_folder

I then need to access a file that is up one level, e.g.,

newpath = D:\data_superfolder

In Matlab to move up one level all i need to do is,

cd('..')

which is super simple, but I've read through the ImageJ user manual I can't find similar code. How do I do this?

Thanks!


Solution 1:

You can append /.. to a directory path to refer to its parent folder.

Here is an example macro that prompts the user to choose a directory, then lists the contents of its parent.

path = getDirectory("Choose a folder");
list = getFileList(path + "/..");
for (i = 0; i < list.length; i++) {
    print(list[i]);
}