Gimp-Forum.net
Sort list in script-fu - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Sort list in script-fu (/Thread-Sort-list-in-script-fu)



Sort list in script-fu - Vnicent - 03-20-2018

Hello, I am trying to make a relatively simple script to aggregate images together using file-glob to browse files.

The problem is that the files are loaded in a seemingly random order and I would need to load the files by alphabetical order.

Is there a way to sort the list returned by the file-glob function? I suppose I could implement my own sorting function in script-fu it should be possible but if something already exists I'd rather just use it.


RE: Sort list in script-fu - Ofnuts - 03-20-2018

Possibly. But then in Python that would just be:

Code:
for file in sorted(glob.glob('*.png')):
 # do you stuff here

Seriously, if you are starting, use Python. Simpler and more powerful: in script-fu, your limits are the tiny interpreter that's built-in. In Python, you limits are 1) a vastly more powerful interpreter and its standard libraries and 2) several thousands additional libraries. In addition Python is a very popular languages, many people can help, and you will find other uses for it.

If you want examples see there. For what you are doing, my ofn-tiles script may contain some useful sample code.


RE: Sort list in script-fu - Vnicent - 03-26-2018

(03-20-2018, 10:21 AM)Ofnuts Wrote: Possibly. But then in Python that would just be:

Code:
for file in sorted(glob.glob('*.png')):
 # do you stuff here

Seriously, it you are starting, use Python. Simpler and more powerful: in script-fu, your limits are the tiny interpreter that's built-in. In Python, you limits are 1) a vastly more powerful interpreter and its standard libraries and 2) several thousands additional libraries. In addition Python is a very popular languages, many people can help, and you will find other uses for it.

If you want examples  see there. For what you are doing, my ofn-tiles script may contain some useful sample code.
Thank you, Indeed I am starting I was not aware you could use Python, I will look into it Smile