Login  Register

Re: Select every other image and move into specific folder

Posted by Krs5 on Nov 01, 2013; 9:23am
URL: http://imagej.273.s1.nabble.com/Select-every-other-image-and-move-into-specific-folder-tp5005416p5005418.html

Dear Rui,

Maybe the code below does what you want (not tested), if I understand correctly what you have in mind. I am not totally sure about this as you have in your code:

for (i=1; i<list.length; i+=2) what would take image nr 1, 3, 5 etc and not 1, 4, 7 what I would expect seeing your description what would be: for (i=1; i<list.length; i+=3). So maybe I misunderstand what you try to do.

-------------------------------------------------------------------------------------
dir = getDirectory("Choose main Directory");///this contains the subdirectory, and tiffs
dir2 = getDirectory("choose the subdirectory folder"); ///this contains the folder specific to each section

list = getFileList(dir);
list2 = getFileList(dir2);
print("number of files in the Directory ="+ list.length);

for (i=1; i<list.length; i++ ) {
        if (endsWith(list[i], ".tif")){
                print(list[i]);
                for (k=0; k<list2.length; k++){
        if (endsWith(list2[k], "/")){
                                for (n=1; n<4; n++){
                                        oldpath= dir + File.separator+  list[i];
              newpath = dir2 + File.separator+  list2[k] + File.separator+ n+".tif"; ///this renames files to 1
                print(newpath);
                print(oldpath);
                File.rename(oldpath, newpath);
                i +=1;
                                }
                        }
                }
        }
}
-------------------------------------------------------------------------------------
Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Centre for Core Biotechnology Services
Unversity of Leicester

http://www.le.ac.uk/biochem/microscopy/home.html

ImageJ workshops 16 and 17 December: http://www.le.ac.uk/biochem/microscopy/ImageJ2013.html


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of thr rui
Sent: 01 November 2013 06:23
To: [hidden email]
Subject: Select every other image and move into specific folder

Hi,

I want to sort files into specific folders.
I have three images for one histological section, that i would like to stitch them later. For instance, E8_001_001, E8_001_002, E8_001_003 (all these three image compose one section), and then E8_002_001...and so on.
I was able to move the first image into the folder name as the first image file individually, such as E8_001_001, E8_002_001.
Then I want to select the every other image that has _002 as last number and move these into the folder that is associated with first image.
For instance, I want to move E8_001_002 image into the E8_001_001 folder that has E8_001_001 image.

So i have wirten the code below,and this works if i rename the every second image to 1. But i would like to keep the original name and just want to move those file into a new folder. But if i add list[i] in the newpath, it moves all the second image into the first folder.
How can fix this?

 dir = getDirectory("Choose main Directory");///this contains the subdirectory, and tiffs
 dir2 = getDirectory("choose the subdirectory folder"); ///this contains the folder specific to each section


        list = getFileList(dir);
        list2 = getFileList(dir2);
        print("number of files in the Directory ="+ list.length);
       n=1;

        for (i=1; i<list.length; i+=2 ) {
                        if (endsWith(list[i], ".tif")){
                                 print(list[i]);
                                for (k=0; k<list2.length; k++){
                        if (endsWith(list2[k], "/")){


                                oldpath= dir + File.separator+  list[i];
                                newpath = dir2 + File.separator+  list2[k]
+ File.separator+ n+".tif"; ///this renames files to 1
                                print(newpath);
                                print(oldpath);

                                File.rename(oldpath, newpath);

                                }
                }}}





Thank you in advance,

Rui

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

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