The Gimp file-glob Plug-In


This is a *very alpha* plugin for Gimp that takes a single globbable filename parameter and returns a comma separated list of filenames matching its input. Its primarily of use in writing Script-Fu scripts to manipulate sets of files without having to reload gimp in batch mode multiple times or to call the script multiple times.

That mentioned, the plug-in seems prety stable to me, it doesn't do that much. I've yet to have it blow up Gimp, so I'd be suprised if you have any problems.

You can download the source here.

Compiling the plugin is best done using gimptool:

myhost> gimptool --build glob.c

Copy the resulting file glob into your plug-in directory. Unlike most other plugins, this one will not show up anywhere in the Gimp user interface. (Hense why its pretty useless except in scripts) ;)

You can test it using the Script-Fu console window by entering something like:

(file-glob "/usr/local/*")

It should return a comma separated list of the files in /usr/local on your system.

A better example is:

(strbreakup (car (file-glob "*.gif")) ",")

This will use the strbreakup script-fu command to split the list into a Scheme-like list that you can use the various car, caar, cdr's and other things to loop through.

(strbreakup (car (file-glob "myfile.gif")) ",")

will return "myfile.gif" by itself. This is useful if you want to modify a script to handle globbable filenames and ordinary filenames. The above line will return a single element list with just the single file specified.

I'm doing some testing with modifying some existing scripts to use this, I'll put some examples here when I've got them working.

Please e-mail me if you find any bugs with the plug-in or have any suggestions. This is my first plug-in and I'm not sure if I'm handing the memory correctly in it. (ie, I'm not sure if I should be using malloc or some other gimp-provided function to allocate the memory for the return string... *please* e-mail me if this isn't the way to do it.)

Update: I changed malloc to g_malloc, as I ran across it being used in a couple other plugins... so now e-mail me if g_malloc isn't the way to do it :)

This has only been tested with Gimp 1.1, it may not work with 1.0, but I'd appreciate knowing if it does...

- George Hartz