Re: [Gimp-developer] Creating unique file names with Script-Fu
saulgo...@flashingtwelve.brickfilms.com wrote: > I hadn't realized that the TinyScheme Extensions had been enabled for > Script-fu. Script-Fu in GIMP uses a subset of the TSX (TinyScheme eXtensions) module. The 'getenv', 'system', and various additional functions which supported use of sockets were left out. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
2010/7/8 Kevin : > Would it not be possible to create a reasonably unique name using the tiny-fu, > ftx extension, (time) function? That should give you a name unique to the > current time, at least if you don't try and use it more than once in the > current second. > > You'd probably still need to do some collision avoidance just to be safe. > > -- > Kevin (via www.gimpusers.com) > Yes, this is another viable possibility. Thanks for your suggestion. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
2010/6/27 Jon Cruz : > > On Jun 23, 2010, at 10:58 AM, Gino D wrote: > >> After doing several tests, my impression is that such a stratagem >> should work well. Nevertheless, I'm not totally sure of its >> infallibility, because, among other things, I don't know if the >> character “!” is really the first valid symbol on all operating >> systems supported by GIMP, > > As a minor note, I can confirm that "!" is not the first valid symbol on all > operating > systems. Most operating systems allow for many more characters than Windows > does. > That's exactly what I feared. However, now it's clear that this kind of problem can be avoided by following the method previously proposed by Rob, which, being based on sorted lists of file names, is sure to be OS independent, unlike the "dir-read-entry" command. Anyway, thanks for the information. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
2010/6/25 Rob Antonishen : > > Add in a merge sort (i used these three functions): > > (define split > (lambda (ls) > ... > (split-h ls ls '() > > (define merge > (lambda (pred ls1 ls2) > ... > (else (cons (car ls2) (merge pred ls1 (cdr ls2))) > > (define merge-sort > (lambda (pred ls) > ... > (merge-sort pred (cdr splits > > Then get a sorted directory like like so: > (set! varFileList (merge-sort string<=? (cadr (file-glob > (string-append varDirectory DIR-SEPARATOR "*") 1 > > -Rob A> > Well done, Rob, and what an interesting revelation! Though not so long ago, indeed, I have collected all the Script-Fu procedures returned by the “oblist” command invocation in a text file, with the purpose of having them always within reach, nevertheless I hadn’t noticed the existence of the “file-glob” procedure before now. Hence, thanks a lot for highlighting this command, as well as for contriving those powerful procedures whereby it is possible to achieve a sorted directory. The approach you suggest is a good alternative to the employment of the “dir-read-entry” procedure, which actually might be unreliable in certain cases, as Saulgoode points out, depending to what kind of filesystem the target directory belongs to. In fact, after obtaining an alphabetically ordered list with the names of the folder's elements, it would be possible to exploit even the last element rather than the first one, by producing a new string that concatenates this ending string, the character “z”, and finally the string “.pat”, so as to get a file name that should be unique and non-confrontational. Thank you again for your contribution. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
On Jun 23, 2010, at 10:58 AM, Gino D wrote: > After doing several tests, my impression is that such a stratagem > should work well. Nevertheless, I'm not totally sure of its > infallibility, because, among other things, I don't know if the > character “!” is really the first valid symbol on all operating > systems supported by GIMP, As a minor note, I can confirm that "!" is not the first valid symbol on all operating systems. Most operating systems allow for many more characters than Windows does. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
> > Your approach would not succeed on GNU/Linux platforms because > 'dir-read-entry' does not ensure that the entries are returned in > alphabetical order. Even on Windows I suspect you will find that the > order entries are retrieved is dependent upon the type of filesystem > (FAT, VFAT, NTFS all behave differently). Add in a merge sort (i used these three functions): (define split (lambda (ls) (letrec ((split-h (lambda (ls ls1 ls2) (cond ((or (null? ls) (null? (cdr ls))) (cons (reverse ls2) ls1)) (else (split-h (cddr ls) (cdr ls1) (cons (car ls1) ls2))) (split-h ls ls '() (define merge (lambda (pred ls1 ls2) (cond ((null? ls1) ls2) ((null? ls2) ls1) ((pred (car ls1) (car ls2)) (cons (car ls1) (merge pred (cdr ls1) ls2))) (else (cons (car ls2) (merge pred ls1 (cdr ls2))) ;pred is the comparison, i.e. <= for an ascending numeric list, or ;string<=? for a case sensitive alphabetical sort, ;string-ci<=? for a case insensitive alphabetical sort, (define merge-sort (lambda (pred ls) (cond ((null? ls) ls) ((null? (cdr ls)) ls) (else (let ((splits (split ls))) (merge pred (merge-sort pred (car splits)) (merge-sort pred (cdr splits Then get a sorted directory like like so: (set! varFileList (merge-sort string<=? (cadr (file-glob (string-append varDirectory DIR-SEPARATOR "*") 1 -Rob A> ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
Quoting Gino D : >> 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. > > Deletion of files is made possible by the “file-delete” procedure, as > shown at the end of the sequence of commands I proposed in my initial > post. I hadn't realized that the TinyScheme Extensions had been enabled for Script-fu. If you choose to use the 'gimp-temp-name' approach I previously proposed then 'file-exists?' would be better than opening the file. >> The following code snippet uses 'gimp-temp-name' -- which generates a >> filename that has an extremely good chance of being unique... > > The idea of employing the “gimp-temp-name” procedure for generating a > most likely unique file name is very interesting. Thanks for your > suggestion and the snippet you devised. Pity that such procedure > affects only the GIMP temporary directory; if it were effective in > every folder, it would be great, especially for the issue we are > discussing. Even within the GIMP temporary directory, 'gimp-temp-name' does not actually guarantee uniqueness against files in the directory, so the only inconvenience of using 'gimp-temp-name' is having to parse out the filename from the full filepath. > By chance, can you tell me if my previous conjectures about the > priority of the exclamation point are correct, besides on Windows, on > other operating systems too? Your approach would not succeed on GNU/Linux platforms because 'dir-read-entry' does not ensure that the entries are returned in alphabetical order. Even on Windows I suspect you will find that the order entries are retrieved is dependent upon the type of filesystem (FAT, VFAT, NTFS all behave differently). ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
Hi. 2010/6/23 : > > 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. > Deletion of files is made possible by the “file-delete” procedure, as shown at the end of the sequence of commands I proposed in my initial post. > > The following code snippet uses 'gimp-temp-name' -- which generates a > filename that has an extremely good chance of being unique... > The idea of employing the “gimp-temp-name” procedure for generating a most likely unique file name is very interesting. Thanks for your suggestion and the snippet you devised. Pity that such procedure affects only the GIMP temporary directory; if it were effective in every folder, it would be great, especially for the issue we are discussing. By chance, can you tell me if my previous conjectures about the priority of the exclamation point are correct, besides on Windows, on other operating systems too? ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Creating unique file names with Script-Fu
Quoting Gino D : > 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 "") (filename "") (port #t)) (while port (set! basename (car (last (strbreakup (car (gimp-temp-name "pat")) "/" (set! filename (string-append "/path/to/directory/" basename)) (set! port (open-input-file filename)) (when port (close-output-port port) ) ) ; 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 Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer