Posted by
rtas on
Nov 01, 2013; 6:22am
URL: http://imagej.273.s1.nabble.com/Select-every-other-image-and-move-into-specific-folder-tp5005416.html
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