Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of files (*. jpg) from all folders?

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.

like image 225
Smirnov Avatar asked Oct 18 '11 11:10

Smirnov


1 Answers

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.

like image 94
Alex D Avatar answered Nov 15 '22 18:11

Alex D