macro rename files simple

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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
|  
Report Content as Inappropriate

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
|  
Report Content as Inappropriate

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
|  
Report Content as Inappropriate

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
|  
Report Content as Inappropriate

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!

Loading...