Import Raw with spaces and special character ] in path

Dear ImageJ users,

I’m trying to write a macro to import raw data where there are both spaces and the special character “]” in the path to the data e.g. /parent/directory [2018-08-08 14.30.00]/dataFile where the text inside [ ] is the date and time the file was created which is written by some closed source software.

Paths containing “]” can be imported with:
run("Raw...", "open="+sourceDir+File.separator+dataFile+" image=...
where sourceDir=full path to the directory

Paths containing spaces can be imported with:
run("Raw...", "open=["+sourceDir+File.separator+dataFile+"] image=...

There is no problem with both spaces and “]” using the drop-down menu File->Import->Raw…, but when using the macro recorder to turn this command into a IJ1 macro, I cannot find a way to handle both spaces and “]”.
The error returned by the macro is:
Read error or file not found (1): /parent/directory [2018-08-08 14.30.00
with the path to the data file terminating at “]”. This happens both when using variables to define the path to the data file and when using a string.

It would be an option to rename the directory so as not to contain special characters, but I would prefer not to if possible.

Thanks for your help


A very similar issue was discussed recently here:

@James_Minto Which version of ImageJ1 are you running?

1 Like

Hi Jan,

Thanks for the reply.

I was running Fiji with IJ 1.51n. Upgrading to 1.52e, as recommended in the link you provided, has solved the problem.

For anyone else interested, the following IJ1 macro code works fine for paths with spaces and the special character “]”:
run("Raw...", "open=["+sourceDir+File.separator+dataFile+"] image=...

Thanks again

1 Like

Dear Jan,

I wasn’t quite sure how to find out the IJ version and how to update it.
Would it have been by copying and pasting the code for each of the five files?

I found in the meantime a different solution which can be simply run before starting your script:
Fix funny file names

Thanks and best wishes,

1 Like