Re: Renaming files

Posted by Jeremy Adler on
URL: http://imagej.273.s1.nabble.com/Renaming-files-tp5023166p5023174.html

Hi Nathalie,
The text Esteban supplied does the heavy lifting - allows you to select a folder, read the names and change them.

There is a simpler version of the renaming part,
based on the name you use - you don't need to "split" and generate an array of pieces

origString="C00XZ00Y";
print("original ",origString);
remove="XZ";// delete.
replacewith="X_Z";// what you want instead.
newSuffix="_t00Z"; // want to add.
newString=replace(origString, remove, replacewith) + newSuffix; ;// replaces every instance of one string with another.
print("new ",newString);

confusingly when I look at the examples from your dropbox, I am unclear how you want to rename these images, the names don't fit the "C00XZ00Y".

Jeremy Adler
BioVis
Uppsala U




-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of G. Esteban Fernandez
Sent: Sunday, April 5, 2020 6:05 PM
To: [hidden email]
Subject: Re: Renaming files

Hi Nathalie,

Herbie's solution is great!  Much easier than what I would've done :-) Just add an extension, like .tif, if your files have one.  I'll add functionality for all files in a folder and add an extension (change the .tif if your files have a different extension):

folder = getDirectory("Choose a folder to rename files"); files = getFileList(folder); for(i = 0; i < files.length; i++){
  nameSplit = split(files[i], "Z");
  newFilename = nameSplit[0] + "_Z" + nameSplit[1] + "_t00Z.tif";
  File.rename(folder + files[i], folder + newFilename); }

-Esteban

On Sun, Apr 5, 2020 at 4:56 AM Herbie <[hidden email]> wrote:

> Good day Nathalie,
>
> concerning labels of type
>
> //
> str = "C00XZ00Y";
> //
> // the following two lines of ImageJ macro code will do // a = split(
> str, "Z" ); str = a[0] + "_Z" + a[1] + "_t00Z"; // print( str );
> exit();
>
> Please try to understand what happen according to these two line by
> studying:
> <https://imagej.nih.gov/ij/developer/macro/functions.html>
>
> I didn't have a look at the provided link.
>
> Regards
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> Houssin, Nathalie Samantha Laetitia wrote
> > Hello,
> >
> > I hope everyone is safe and coping with the sanitary situation.
> > I am trying to rename batch of files and have not been able to come
> > up with a solution not too time consuming My files are labeled with
> > C00XZ00Y and I would like to put a string in between as well as add
> > the suffix _t00Z so that it would look like C00X_Z00Y_t00Z My stacks
> > are comprised of 25 to 40 images with 3 channels Thank you for any
> > help you can provide with this
> >
> > Bests,
> >
> > Nathalie
> >
> > Here is a link if you want to see the filenames
> >
> https://www.dropbox.com/sh/4qc2e1qyq1b4vr8/AAC9kPzGvFXE-8rzN5eD95Epa?d
> l=0
> >
> >
> > Nathalie HOUSSIN, PhD
> > Ohio State University - College of Optometry Plageman's Lab Fry Hall
> > room 341c
> > 338 W 10th avenue
> > Columbus, Ohio 43210
> > Tel: 614-292-3346
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>
>
>
>
> --
> 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








När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy

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