Posted by
Krs5 on
Apr 21, 2017; 7:56am
URL: http://imagej.273.s1.nabble.com/How-do-you-open-files-that-have-brackets-in-the-filename-in-a-macro-tp5018579p5018583.html
Dear Jeff
You could replace them using
file = "awkward_filename_[39254,8006]_component_data.tif";
bracketPattern = "(\\[)";
bracketPattern2 = "(\\])";
addBackslashPattern = "\\\\";
escapedFile = replace(file, bracketPattern, addBackslashPattern);
escapedFile = replace(escapedFile, bracketPattern2, addBackslashPattern);
results in: awkward_filename_\39254,8006\_component_data.tif
However, I would not even insert a \ but just replace it with "" so that you end up with: awkward_filename_39254,8006_component_data.tif as an \ also will introduce problems.
However, I am also able to open the file when using:
open("C:\\TEMP\\awkward_filename_\[39254,8006\]_component_data.tif");
although the text between "" has the wrong colour in the Fiji editor, green/greyish instead of magenta.
Best wishes
Kees
Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aifImageJ workshops 1 and 2 June:
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/AIF/workshops/imagej-workshops-June-2017-----Original Message-----
From: Jeff C Hanson [mailto:
[hidden email]]
Sent: 20 April 2017 19:52
To:
[hidden email]
Subject: How do you open files that have brackets in the filename in a macro?
I'm stumped. I have a batch of files that I want to analyze with a macro. When the macro tries to open the files, it cuts the filename off at the close bracket (]). I tried throwing in a \ to escape the embedded brackets, but, it didn't help.
Is there a way to open the files in a way that doesn't treat the brackets as a special character? Or, is there a way to get it to ignore the brackets in the middle of the filename?
Thanks,
Jeff
ps - Here's an example of what I was trying to do...
file = "awkward_filename_[39254,8006]_component_data.tif";
bracketPattern = "([\\[\\]])";
addBackslashPattern = "\\\\$1";
escapedFile = replace(file, bracketPattern, addBackslashPattern);
// This throws an exception, because it cuts the filename off at the "]" -- and says the file does not exist //run("Bio-Formats", "open=["+file+"] color_mode=Default open_all_series view=Hyperstack stack_order=XYCZT"); // This didn't fix it. :-( run("Bio-Formats", "open=["+escapedFile+"] color_mode=Default open_all_series view=Hyperstack stack_order=XYCZT");
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html