How do you open files that have brackets in the filename in a macro?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How do you open files that have brackets in the filename in a macro?

jchanson
                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
Reply | Threaded
Open this post in threaded view
|

Re: How do you open files that have brackets in the filename in a macro?

Cammer, Michael
I think I had this problem with files from a Zeiss lightsheet two years ago and I renamed the files in a cmd window (Win7) with something like:
ren ??????[??]*.tif ??????x??x*.tif

=*===========================================================*=
 Michael Cammer, DART Microscopy Laboratory, NYU Langone Medical Center
    Cell:  914-309-3270 (this is for calling, not texting)    Office: Skirball 2nd Floor main office, back right
      http://ocs.med.nyu.edu/microscopy & http://microscopynotes.com/
http://nyusackler.university-tour.com/15/34/core-laboratories-and-shared-resources/microscopy-core
http://nyusackler.university-tour.com/15/32/core-laboratories-and-shared-resources/introduction



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Jeff C Hanson
Sent: Thursday, April 20, 2017 2:52 PM
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: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQIFAg&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=2yYBHUtxfF67-1Pwyy2vuXjnxvRQDXJykI-H5qVvl0Y&s=w00Dih_BCgXNa9ZmLV9aERtTdvc4Z49p_5-zBvRI9oU&e= 

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How do you open files that have brackets in the filename in a macro?

Krs5
In reply to this post by jchanson
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/aif

ImageJ 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
Reply | Threaded
Open this post in threaded view
|

Re: How do you open files that have brackets in the filename in a macro?

jchanson
In reply to this post by jchanson
Thanks for the tips on dealing with filenames with brackets in them.  Renaming the files so they didn't have brackets would be the easiest thing to do -- thanks, Michael for the simple windows command for stripping them out.  However, just using the plain "open" command worked, too (thanks, Kees for showing that it worked).  With some googling, I was able to find the macro extension command equivalent of the open command to use BioFormats.  The following was able to open my file with brackets in the filename:

// Load Bio-Formats extensions so that the "Ext." bioformats commands are available.
run("Bio-Formats Macro Extensions");
file = "awkward_filename_[39254,8006]_component_data.tif";
Ext.openImagePlus(file);


Thanks again everyone,
Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How do you open files that have brackets in the filename in a macro?

Stoyan Pavlov
Or you could simply use a file renaming tool like AntRenamer ?(
http://www.antp.be/software/renamer/features)

На 21.04.2017 г. 5:41 сл.об. "Jeff C Hanson" <[hidden email]>
написа:

> Thanks for the tips on dealing with filenames with brackets in them.
> Renaming the files so they didn't have brackets would be the easiest thing
> to do -- thanks, Michael for the simple windows command for stripping them
> out.  However, just using the plain "open" command worked, too (thanks,
> Kees for showing that it worked).  With some googling, I was able to find
> the macro extension command equivalent of the open command to use
> BioFormats.  The following was able to open my file with brackets in the
> filename:
>
> // Load Bio-Formats extensions so that the "Ext." bioformats commands are
> available.
> run("Bio-Formats Macro Extensions");
> file = "awkward_filename_[39254,8006]_component_data.tif";
> Ext.openImagePlus(file);
>
>
> Thanks again everyone,
> Jeff
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How do you open files that have brackets in the filename in a macro?

CARL Philippe (LBP)
Dear написа:,
In the case you want to go into this direction, you can indeed dowload an ad hoc tool for each needed application (files renaming, files comparison, FTP,...).
Or rather use a kind of "Swiss knife" tool as Total Commander:
https://www.ghisler.com/index.htm
which will allow you to do all this in one:
https://www.ghisler.com/screenshots/en/06.html
https://www.ghisler.com/screenshots/en/07.html
https://www.ghisler.com/screenshots/en/04.html
...
Have  nice week-end,
Philippe

Le Samedi 29 Avril 2017 23:07 CEST, Stoyan Pavlov <[hidden email]> a écrit:

> Or you could simply use a file renaming tool like AntRenamer ?(
> http://www.antp.be/software/renamer/features)
>
> На 21.04.2017 г. 5:41 сл.об. "Jeff C Hanson" <[hidden email]>
> написа:
>
> > Thanks for the tips on dealing with filenames with brackets in them.
> > Renaming the files so they didn't have brackets would be the easiest thing
> > to do -- thanks, Michael for the simple windows command for stripping them
> > out.  However, just using the plain "open" command worked, too (thanks,
> > Kees for showing that it worked).  With some googling, I was able to find
> > the macro extension command equivalent of the open command to use
> > BioFormats.  The following was able to open my file with brackets in the
> > filename:
> >
> > // Load Bio-Formats extensions so that the "Ext." bioformats commands are
> > available.
> > run("Bio-Formats Macro Extensions");
> > file = "awkward_filename_[39254,8006]_component_data.tif";
> > Ext.openImagePlus(file);
> >
> >
> > Thanks again everyone,
> > Jeff
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html





--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html