REBOL [
    Title: "Gather PDF filenames"
    Purpose: {In a specified folder, find all the PDF files in that
    folder and all subfolders. Copy them to a specified destination folder}
]

;; [---------------------------------------------------------------------------]
;; [ This is a quick-and-dirty program written for a specific purpose.         ]
;; [ The purpose was to gather PDF files from a folder and its subfolders,     ]
;; [ and copy them to a destination folder so they could be zipped and sent    ]
;; [ to interested people.                                                     ]
;; [ This is an example of how REBOL can be used in daily life to make         ]
;; [ tedious chores easier.  All the PDF files in a folder could be dragged    ]
;; [ and dropped to a destination in a short time if there are not too         ]
;; [ many but when the number gets large, a little helper is valuable.         ]
;; [---------------------------------------------------------------------------]

do %RecursiveFolderFileLists.r
do %FilesOfTypeInList.r

SOURCE-SELECTED: false
DESTINATION-SELECTED: false
SOURCE-FOLDER: none
DESTINATION-FOLDER: none
PDF-LIST: none

SELECT-SOURCE-FOLDER: does [
    if not SOURCE-FOLDER: request-dir [
        alert "Source selection canceled"
        exit
    ]
    set-face MAIN-SOURCE to-string SOURCE-FOLDER
    SOURCE-SELECTED: true
]

SELECT-DESTINATION-FOLDER: does [
    if not DESTINATION-FOLDER: request-dir [
        alert "Destination selection canceled"
        exit
    ]
    set-face MAIN-DESTINATION to-string DESTINATION-FOLDER
    DESTINATION-SELECTED: true
]

GATHER-FILES: does [
    if not SOURCE-SELECTED [
        alert "Source folder not specified"
        exit
    ]
    if not DESTINATION-SELECTED [
        alert "Destination folder not specified"
        exit
    ]
    FIND-FILES-RECURSE SOURCE-FOLDER
    PDF-LIST: copy []
    PDF-LIST: FILES-OF-TYPE-IN-LIST RECURSIVE-FILE-LIST [%.pdf %.PDF]
;;  PDF-LIST contains full path names
    change-dir DESTINATION-FOLDER
    foreach ID PDF-LIST [
        print ["Copying " ID]
        write/binary second split-path ID read/binary ID
    ]
    alert "Done." 
]

MAIN-WINDOW: layout [
    across
    banner "Gather PDF files"
    return
    button 200 "Select source folder" [SELECT-SOURCE-FOLDER]
    MAIN-SOURCE: info 300
    return
    button 200 "Select destination folder" [SELECT-DESTINATION-FOLDER]
    MAIN-DESTINATION: info 300
    return
    button 120 "Gather files" [GATHER-FILES]
    button "Quit" [quit]
    button "Debug" [halt]
]

view center-face MAIN-WINDOW