;
; Version 1.0 07.02.2012 for ????

; See http://

(define selffilename "\n- batch_template.scm")

; Batch mode wrapper
(define (batch_template file_extension destination_directory)
  (let* 
    (
      (destination_file "")
      (varFileList (cadr (file-glob (string-append "*" file_extension) 1))) ; make a list of all the files that match the file extension

      ; Adjust these values to suit     
    )
    (gimp-message-set-handler ERROR-CONSOLE)
    (if (not (file-exists? destination_directory))
      (error (string-append "Error: directory " destination_directory " doesn't exist"))
      (if (= (file-type destination_directory) FILE-TYPE-DIR)
        ()
        (error (string-append destination_directory " is not a directory"))
      )
    )
    
    ; loop through all the files in the list
    (for-each
      (lambda (filename)
;             Thing to do goes here
              (my-single-file-code filename destination_directory)
      )
      varFileList
    )
  )
)

; Here's the code to process a single image
(define (my-single-file-code filename destination_directory)
  (let* (
          (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))  ; load the image
          (drawable (car (gimp-image-flatten image)))
          (destination_file (string-append destination_directory DIR-SEPARATOR filename))
        )
    (gimp-message (string-append "processing-" filename)) 

    ; Do something here
    
    (gimp-file-save RUN-NONINTERACTIVE image drawable destination_file destination_file)
    (gimp-image-delete image)                  ; unload the image           
  )
)

(define (script-fu-interactive_batch_template destination_directory file_extension)                     
  (let* (
        )
        (batch_template file_extension destination_directory)
  )
)

(script-fu-register "script-fu-interactive_batch_template"
                    "Interactive Batch Template..."
                    (string-append "Interactive front end to batch template " selffilename)
                    "I did this"
                    "GPL License"
                    "2021/06/11"
                    ""
                    SF-DIRNAME _"Destination Directory" "destination"
                    SF-STRING _"Extension" ".png"
)

(script-fu-menu-register "script-fu-interactive_batch_template" "<Image>/contributed")

; command line for Windows:
; "C:\Program Files\GIMP-2.0\bin\gimp-2.6.exe" -i -f -d --verbose -b "(batch_template \".png\" \"destination\")" -b "(gimp-quit 0)"

; change \"destination\" to \".\" to overwrite existing files 
