7

How do I get a list of files (*.jpg) from all folders, using Script-FU in GIMP?

(let* ((filelist (cadr (file-glob pattern 1)))

This only gets files from the current folder.

Vsevolod Dyomkin
  • 9,343
  • 2
  • 31
  • 36
Smirnov
  • 153
  • 1
  • 1
  • 9
  • Script-Fu is TinyScheme, which is a very limited Scheme interpreter. I think it can not do it. – ceving Nov 12 '11 at 20:51
  • @Smirnov, check out my answer... someone finally figured out the answer to your question after all these months! – Alex D Feb 09 '12 at 11:46

1 Answers1

2

It will be a bit complicated, but it can be done. The list of files which file-glob returns for the current directory includes subdirectories. So you can use that list to recursively build more glob strings, which can be passed to file-glob, and so on.

(define separator "\\") ; I am using Windows
(define (all-files dir)
  (let* ((patt  (string-append dir separator "*"))
         (files (cadr (file-glob patt 1))))
    (append files (search-dirs files))))
(define (search-dirs dirs)
  (if (null? dirs)
      (list)
      (append (all-files (head dirs)) (search-dirs (tail dirs)))))

This works, but it is slow. Perhaps you can find a way to make it faster?

By the way, this returns all files, not just JPGs. To make it return only JPGs, modify the line which says "(append files (search-dirs files))". Rather than appending "files", filter out the JPGs and append those only.

Alex D
  • 29,755
  • 7
  • 80
  • 126