> 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)
                              ((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)
          ((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)
          ((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

Reply via email to