Login  Register

Re: Select every other image and move into specific folder

Posted by James Ewing on Nov 01, 2013; 6:23pm
URL: http://imagej.273.s1.nabble.com/Select-every-other-image-and-move-into-specific-folder-tp5005416p5005424.html

Rui - I suggest that you change the case of the filename for the directory, because that is what is causing you trouble  - you shouldn't duplicate file names, with one a directory and the other an ordinary file. If your ordinary files are E8-something, make the directory e8-something, or vice-versa. alternatively, you could add a leading or trailing string, i.e. D_E8-something.
 - Jim

On Nov 1, 2013, at 1:21 PM, rtas <[hidden email]> wrote:

> I did not describe clearly.
> Essentially I have many images in main folder and images are consist of
> three images as one set.
> These one set of three images (E8_001_001, E8_001_002, E8_001_003) need to
> go one folder.
> Then next  one set of three images (ie. E8_002_001, E8_002_002, E8_002_003)
> need to go another folder.
> I want to keep original image file name and the folder name can be same as
> first image file (E8_001_001, E8_002_001..).  
> If i could do this as one code that would be great. But i do not know how.
> so i separate code as three steps:
> first code; select every first image out of three and create the individual
> folder
> second code: select every second image out of three and move them into the
> folder that is associated with the first image
> third code: select every third image out of three and move them into the
> folder that is associated with first and second image. (i don't have this
> yet since the second code has problem of the file name)  
>
>
> I have the other code before this as you suggested to use i+=3 instead of 2,
> as first code as below:
>
> //Get the directory
>  dir = getDirectory("Choose a Directory ");
>  SaveDir = getDirectory("Choose a Sort Save Directory ");
>
> //Create file list
>        list = getFileList(dir);
>        print("number of files in the Directory ="+ list.length);
>
> //Look throug the list - and move the files to
>        for (i=0; i<list.length; i+=3 ) {
>                        if (endsWith(list[i], "/")){
>                                //listFiles(""+SubDirNames[0]+list[i]);
>                        }else{
>                        //Split the Name by "." and look at the first Entry
>                                Data = split(list[i],".");
>
>                        // Make directory name
>                                DirName = Data[0];
>
>                        //Ceate that directory
>                                File.makeDirectory(SaveDir+File.separator+
> DirName);
>
>                                                 // Move the file to that
> Dir
>                                File.rename(dir + list[i],SaveDir + DirName
> + File.separator + list[i]);
>
>                                }
>                }
>
>
>
>
> Then the second code is the one i listed as previous post:
>
> 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);
>
>                                }
>                }}}
>
> The problem here is the file name. I cannot keep the original file name and
> move those into the associated folders.
> I appreciate any suggestion.
>
> Rui
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Select-every-other-image-and-move-into-specific-folder-tp5005416p5005423.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