Login  Register

Re: macro rename files simple

Posted by Herbie on May 06, 2016; 3:18pm
URL: http://imagej.273.s1.nabble.com/macro-rename-files-simple-tp5016330p5016336.html

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