Posted by
ved sharma on
Nov 23, 2011; 5:40pm
URL: http://imagej.273.s1.nabble.com/File-import-sort-names-numerically-not-working-tp3682440p3682442.html
Hi Herbie,
Yes, changing the file name from t1.tif -> t01.tif helped me sort the files numerically. I realized that renaming can be done in ImageJ itself. So I wrote a little macro and I'm attaching it here(see below) if someone else wants to use it. Currently it is only doing two running digits, but can be easily extended to 3, 4 or more digits.
// start
macro "pad_zeros"{
dir = getDirectory("Choose a Directory");
filelist = getFileList(dir);
for (i=0; i<filelist.length; i++) {
if(endsWith(filelist[i], ".tif")) {
index = lastIndexOf(filelist[i], ".");
a = substring(filelist[i], index-1, index);
b = substring(filelist[i], index-2, index-1);
if(!isNaN(a) && isNaN(b)) {
old = substring(filelist[i], index-1);
new = replace(filelist[i], old, "0"+old);
flag = File.rename(dir+filelist[i], dir+new);
}
}
}
}
// end
Ved
PS: Text editor or the browser adds "amp;" in the second if statement, which you'll need to delete to run this macro.
On Wed, 23 Nov 2011 10:57:24 +0100, Rainer M. Engel <
[hidden email]> wrote:
>Am 22.11.2011 18:59, schrieb Herbie:
>>> Dear ImageJ users,
>>>
>>> I'm trying import->Image sequence in a directory, which contains 44
>>> files. File names are:
>>>
>>> 01_s1_t1.tif, ..., 01_s1_t11.tif
>>> 01_s2_t1.tif, ..., 01_s2_t11.tif
>>> 02_s1_t1.tif, ..., 02_s1_t11.tif
>>> 02_s2_t1.tif, ..., 02_s2_t11.tif
>>>
>>> To import all the files containing "s1", I enter "s1" in the field
>>> "File name contains:" and check "Sort names numerically". But I find
>>> that the files ending with "t10.tif" and "t11.tif" do not appear after
>>> "t9.tif", rather they appear at the end of the stack. Is this a bug?
>>> Is there a better way to import these files?
>>>
>>> I'm running ImageJ 1.46b5 on a Windows 7 machine.
>>>
>>> Ved
>>
>> What about using t09.tiff instead of t9.tiff ?
>>
>> If this poses problems, then you might use a utility for batch renaming
>> files before you open them in IJ. I don't know about such utilities for
>> Windows but they must exist and most probably some of them are free.
>>
>> HTH
>>
>> Herbie
>>
>> ------------------------
>> <
http://www.gluender.de>
>>
>>
>
>On Windows I would recommend these free tools..
>
http://www.bulkrenameutility.co.uk>or
http://www.xnview.com/>
>Interesting read Norbert and I would second your suggestion.
>
>regards,
>Rainer