macro rename files simple

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

macro rename files simple

inesica
Hello everybody. I would be very grateful if you could help me create a macro in image J:

- I open images in format (z000x_t000y, where y stays constant) that I want to save with a new name. I want to change the X value by adding or subtracting a certain value m (x+/-m). For example for z0005_t0000, z0006_t0000, z0007_t0000, if my m is -4, i would like to save the files as z0001_t0000, z0002_t0000, z0003_t0000 etc.

Thank you very much in advance for your help.
Reply | Threaded
Open this post in threaded view
|

Re: macro rename files simple

Herbie
Inesica,

is this

//----------------------------------------------------
m = -4;
name = "z0007_t0000";
number  =  parseInt( substring( name, 1, 5 ) );
number +=m ;
//if ( number < 10 ) { name = "z000"; } else { name = "z00"; }
name = "z" + IJ.pad( number, 4 ) + "_t0000";
print( name );
//----------------------------------------------------

what you are looking for?

You've ask a very similar question before and of course the answer is
rather similar...

You may have a look at
<http://rsb.info.nih.gov/ij/developer/macro/functions.html>
for the available ImageJ-macro functions.

Best

Herbie

:::::::::::::::::::::::::::::::::::::
Am 06.05.16 um 14:27 schrieb inesica:

> Hello everybody. I would be very grateful if you could help me create
> a macro in image J:
>
> - I open images in format (z000x_t000y, where y stays constant) that
> I want to save with a new name. I want to change the X value by
> adding or subtracting a certain value m (x+/-m). For example for
> z0005_t0000, z0006_t0000, z0007_t0000, if my m is -4, i would like to
> save the files as z0001_t0000, z0002_t0000, z0003_t0000 etc.
>
> Thank you very much in advance for your help.
>
>
>
> -- View this message in context:
> http://imagej.1557.x6.nabble.com/macro-rename-files-simple-tp5016330.html
>
>
Sent from the ImageJ mailing list archive at Nabble.com.
>
> -- 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: macro rename files simple

inesica
Hello,
Thank you very much for your response.
However, I would like to do this for many files that are opened, not only for "z0007_t0000" as in your example and I would like to save them automatically with the new name.
How can I do that?
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: macro rename files simple

Herbie
Inesica,

I assumed that you could do the batch processing yourself by using the
appropriate ImageJ-macro functions. The macro language is really easy!

This macro works for me:
//----------------------------------------------------
setBatchMode( true );
m = -4;
dirPath = getDirectory( "Choose a Directory" );
nameArray = getFileList( dirPath );
for ( i = 0; i < nameArray.length; i++ ) {
   number = parseInt( substring( nameArray[i], 1, 5 ) );
   number += m;
   name = "z" + IJ.pad( number, 4 ) + "_t0000.tif";
   status = File.rename( dirPath + nameArray[i], dirPath + name );
   if ( status == false ) { exit( "Could not rename" ); }
}
setBatchMode( false );
//----------------------------------------------------

Hope you are well-served

Herbie

:::::::::::::::::::::::::::::::::::::
Am 06.05.16 um 15:46 schrieb inesica:

> Hello, Thank you very much for your response. However, I would like
> to do this for many files that are opened, not only for "z0007_t0000"
> as in your example and I would like to save them automatically with
> the new name. How can I do that? Thank you.
>
>
>
> -- View this message in context:
> http://imagej.1557.x6.nabble.com/macro-rename-files-simple-tp5016330p5016333.html
>
>
Sent from the ImageJ mailing list archive at Nabble.com.
>
> -- 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: macro rename files simple

inesica
Hello, thanks a lot!! However, I wanted to update the macro. Y is no longer constant and varies from 0 to 40 for ex. (t0000 to t0040). How could I add this to the macro and make the program work for the totality of t (from t0000 to t0040 for example)?
Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: macro rename files simple

inesica
In reply to this post by Herbie
Hello, could you help me with another problem that I have renaming ImageJ
files? I try to adapt the macro you gave me earlier, but I seem to be
missing something. My files have these names: z0000_t0000, z0000_t0002,
z0000_t0004 etc (until z0032_t0080) and I would like to rename z0000_t0002
to z0000_t0001; z0000_t0004 to z0000_t0002 etc; which basically means divide
the number at the end by 2. So I adapted your function to:

setBatchMode( true );
*m = /2; *
dirPath = getDirectory( "Choose a Directory" );
nameArray = getFileList( dirPath );
for ( i = 0; i < nameArray.length; i++ ) {
   number = parseInt( substring( nameArray[i], 7, 11 ) );
   number += m;
   name = substring(nameArray[i], 0, 6) + "t" + IJ.pad( number, 4 ) +
".tif";
   status = File.rename( dirPath + nameArray[i], dirPath + name );
   if ( status == false ) { exit( "Could not rename" ); }
}
setBatchMode( false );


but it does not seem to work. How can I change it to make it work?

Thank you very much in advance.



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: macro rename files simple

Herbie
Good day!

Replace line "number += m;" by "number /= 2;" (of course without the
inverted commas) and please try to learn macro coding which is really easy:
<https://imagej.nih.gov/ij/developer/macro/macros.html>
<https://imagej.nih.gov/ij/developer/macro/functions.html>

Regards

Herbie

:::::::::::::::::::::::::::::::::::::
Am 05.03.18 um 11:15 schrieb inesica:

> Hello, could you help me with another problem that I have renaming ImageJ
> files? I try to adapt the macro you gave me earlier, but I seem to be
> missing something. My files have these names: z0000_t0000, z0000_t0002,
> z0000_t0004 etc (until z0032_t0080) and I would like to rename z0000_t0002
> to z0000_t0001; z0000_t0004 to z0000_t0002 etc; which basically means divide
> the number at the end by 2. So I adapted your function to:
>
> setBatchMode( true );
> *m = /2; *
> dirPath = getDirectory( "Choose a Directory" );
> nameArray = getFileList( dirPath );
> for ( i = 0; i < nameArray.length; i++ ) {
>     number = parseInt( substring( nameArray[i], 7, 11 ) );
>     number += m;
>     name = substring(nameArray[i], 0, 6) + "t" + IJ.pad( number, 4 ) +
> ".tif";
>     status = File.rename( dirPath + nameArray[i], dirPath + name );
>     if ( status == false ) { exit( "Could not rename" ); }
> }
> setBatchMode( false );
>
>
> but it does not seem to work. How can I change it to make it work?
>
> Thank you very much in advance.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> 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: macro rename files simple

CARL Philippe (LBP)
In reply to this post by inesica
Dear Inesica,
Probably one of the most important rule when you are debugging a code, is to use and highly abuse with outputs (in the macro language outputs are done with the instruction print) where you compare these output with what you were actually expecting.
And remember: "practice makes perfect"!!!
My best regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Herbie Envoyé : lundi 5 mars 2018 12:57 À : [hidden email] Objet : Re: macro rename files simple

Good day!

Replace line "number += m;" by "number /= 2;" (of course without the inverted commas) and please try to learn macro coding which is really easy:
<https://imagej.nih.gov/ij/developer/macro/macros.html>
<https://imagej.nih.gov/ij/developer/macro/functions.html>

Regards

Herbie

:::::::::::::::::::::::::::::::::::::
Am 05.03.18 um 11:15 schrieb inesica:

> Hello, could you help me with another problem that I have renaming
> ImageJ files? I try to adapt the macro you gave me earlier, but I seem
> to be missing something. My files have these names: z0000_t0000,
> z0000_t0002,
> z0000_t0004 etc (until z0032_t0080) and I would like to rename
> z0000_t0002 to z0000_t0001; z0000_t0004 to z0000_t0002 etc; which
> basically means divide the number at the end by 2. So I adapted your
> function to:
>
> setBatchMode( true );
> *m = /2; *
> dirPath = getDirectory( "Choose a Directory" ); nameArray =
> getFileList( dirPath ); for ( i = 0; i < nameArray.length; i++ ) {
>     number = parseInt( substring( nameArray[i], 7, 11 ) );
>     number += m;
>     name = substring(nameArray[i], 0, 6) + "t" + IJ.pad( number, 4 ) +
> ".tif";
>     status = File.rename( dirPath + nameArray[i], dirPath + name );
>     if ( status == false ) { exit( "Could not rename" ); } }
> setBatchMode( false );
>
>
> but it does not seem to work. How can I change it to make it work?
>
> Thank you very much in advance.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> 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