Quoting Gino D <ginodo...@gmail.com>:
> I'm working on a script in which I would like to insert a sequence of
> commands aimed to save a drawable as PAT file and eventually, when no
> longer needed, eliminate the file in question.
I do not believe it is possible for a Script-fu to delete files. You
will need to either do this outside of GIMP or write a plug-in.
> The problem is that I can’t choose whatever arbitrary name for the PAT
> file, because the destination folder might contain a file with the
> same name, which would therefore run the risk of being overwritten and
> lastly removed by the script. So, this observation points out the
> necessity of implementing a method for creating unique file names by
> means of the Scipt-Fu language.
> Can anyone clarify my doubts and definitely confirm or deny the
> effectiveness of the method I have just stated? Moreover, any
> suggestions on how to generate unique file names in a different and
> simpler way?
I don't have time right now to review your approach, however, ...
The following code snippet uses 'gimp-temp-name' -- which generates a
filename that has an extremely good chance of being unique -- however,
just to be certain, an attempt is made to open the file (in your
directory, not the ~/.gimp/tmp directory). If the open succeeds, the
file is closed and the process repeated.
(let ((basename "")
(set! basename (car (last (strbreakup (car (gimp-temp-name "pat")) "/"))))
(set! filename (string-append "/path/to/directory/" basename))
(set! port (open-input-file filename))
; filename is unique & of the form "/path/to/directory/gimp-temp-######.pat"
For better cross-platform support, you should replace the slashes
above with the DIR-SEPARATOR system constant.
Gimp-developer mailing list