Sort file list more then 10 files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sort file list more then 10 files

Simon Pfandler
Hello

I wrote a macro to analyse steel ball bearings on radiographs. Analysing works fine, but the sorting of the file list cause me some troubels:

I have 13 radigraphs named 1,2,3...,12,13.
When i grab them with "getfilelist" and sort the array. The array is always sorted 1,10,11,12,13,2,3,4...,8,9.
Is there a simple solution to get the files in a proper sequence?

My codesection:
dir=getDirectory("Choose the Image Directory")
list = getFileList(dir);
Array.sort (list);

Thanks
Simon Pfandler
Medizintechniker
Univ.-Klinik für Strahlentherapie - Radioonkologie
Medizinische Universität Innsbruck / Tirol Kliniken GmbH  
Anichstrasse 35, A-6020 Innsbruck

Reply | Threaded
Open this post in threaded view
|

Re: Sort file list more then 10 files

Schebique
hi
Rename files like 01, 02...09.
Great batch rename tool has Total Commander. In linux Krename works well
for me.

Best Ondrej
Dne 14.10.2016 8:12 "Simon Pfandler" <[hidden email]> napsal(a):

> Hello
>
> I wrote a macro to analyse steel ball bearings on radiographs. Analysing
> works fine, but the sorting of the file list cause me some troubels:
>
> I have 13 radigraphs named 1,2,3...,12,13.
> When i grab them with "getfilelist" and sort the array. The array is always
> sorted 1,10,11,12,13,2,3,4...,8,9.
> Is there a simple solution to get the files in a proper sequence?
>
> My codesection:
> dir=getDirectory("Choose the Image Directory")
> list = getFileList(dir);
> Array.sort (list);
>
> Thanks
> Simon Pfandler
> Medizintechniker
> Univ.-Klinik für Strahlentherapie - Radioonkologie
> Medizinische Universität Innsbruck / Tirol Kliniken GmbH
> Anichstrasse 35, A-6020 Innsbruck
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.
> com/Sort-file-list-more-then-10-files-tp5017373.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
Reply | Threaded
Open this post in threaded view
|

Re: Sort file list more then 10 files

Simon Pfandler
Hi

Yes, the extern solution is how it works now. I would like to implement this funktion in the macro, in this case not every user have to do a work around.

thanks
Simon
Reply | Threaded
Open this post in threaded view
|

Re: Sort file list more then 10 files

Herbie
In reply to this post by Simon Pfandler
Dear Simon,

the following works though it isn't very elegant:

////////////////////////////////////
dir=getDirectory("Choose the Image Directory")
list = getFileList(dir);
for (i=0; i<list.length; i++) {
    list[i] = parseInt( replace( list[i], ".tif", ""  ) );
}
Array.sort( list );
Array.show( list );
////////////////////////////////////

The idea is to convert the strings to integers.

Best

Herbie

:::::::::::::::::::::::::::::::::::::
Am 14.10.16 um 08:12 schrieb Simon Pfandler:

> Hello
>
> I wrote a macro to analyse steel ball bearings on radiographs. Analysing
> works fine, but the sorting of the file list cause me some troubels:
>
> I have 13 radigraphs named 1,2,3...,12,13.
> When i grab them with "getfilelist" and sort the array. The array is always
> sorted 1,10,11,12,13,2,3,4...,8,9.
> Is there a simple solution to get the files in a proper sequence?
>
> My codesection:
> dir=getDirectory("Choose the Image Directory")
> list = getFileList(dir);
> Array.sort (list);
>
> Thanks
> Simon Pfandler
> Medizintechniker
> Univ.-Klinik für Strahlentherapie - Radioonkologie
> Medizinische Universität Innsbruck / Tirol Kliniken GmbH
> Anichstrasse 35, A-6020 Innsbruck
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Sort-file-list-more-then-10-files-tp5017373.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
Reply | Threaded
Open this post in threaded view
|

Re: Sort file list more then 10 files

Michael Schmid
In reply to this post by Simon Pfandler
Hi Simon,

if you import the files as image sequence, you can choose to sort the
files numerically. Use 'Virtual stack' if a stack with all files would
use too much memory.

Alternatively, if the file names are all equal except for the numbers,
extract the numbers from the array elements with 'replace', then
parseInt. Then sort the numbers and use string concatenation to creat
the filenames from them. If the file name contains no numerical digits
except for the beginning, try something like this:

   num = parseInt(replace(filename, "[^0-9]", ""));
   nonNumPart = replace(filename, "[0-9]","");
   // sort
   filename = num + nonNumPart;


Michael
________________________________________________________________
On 2016-10-14 08:12, Simon Pfandler wrote:

> Hello
>
> I wrote a macro to analyse steel ball bearings on radiographs. Analysing
> works fine, but the sorting of the file list cause me some troubels:
>
> I have 13 radigraphs named 1,2,3...,12,13.
> When i grab them with "getfilelist" and sort the array. The array is always
> sorted 1,10,11,12,13,2,3,4...,8,9.
> Is there a simple solution to get the files in a proper sequence?
>
> My codesection:
> dir=getDirectory("Choose the Image Directory")
> list = getFileList(dir);
> Array.sort (list);
>
> Thanks
> Simon Pfandler
> Medizintechniker
> Univ.-Klinik für Strahlentherapie - Radioonkologie
> Medizinische Universität Innsbruck / Tirol Kliniken GmbH
> Anichstrasse 35, A-6020 Innsbruck
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Sort-file-list-more-then-10-files-tp5017373.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
Reply | Threaded
Open this post in threaded view
|

Re: Sort file list more then 10 files

Simon Pfandler
In reply to this post by Herbie
Herbie:
Yes thats the solution, not very elegant but working. I had to replace the .tiff with .bmp and everything works fine.
I was a little bit confused, the array of file names is a string, even when there are only integers in it.

Michael:
Image sequence did not work properly with my funktion. I have to do two analyses with different threshholds, so i close the image and open it again.
The second solution sounds good, for more characters, but i only have the numbers 1-13 in the file name, no other information, so Herbies solution works great.

Thanks to all
Simon