REBOL [
    Title: "Change file ID suffix"
    Purpose: {Little helper function to modify the suffix of a file name.}
]

;; [---------------------------------------------------------------------------]
;; [ This is a little helper function that could just as well be written       ]
;; [ in-line in a program, IF, one could remember from time to time how        ]
;; [ to do it.  So instead of memorizing the way to do it, we encapsulated     ]
;; [ it into a function that is a bit easier to remember.                      ]
;; [ The function needs a file name in the generally-standard form of the      ]
;; [ name of a file and a suffix after a dot, and a new suffix, and will       ]
;; [ return a file name that is the same as the supplied file name but         ]
;; [ with the new suffix.                                                      ]
;; [---------------------------------------------------------------------------]

CHANGE-SUFFIX: func [
    FILE-ID
    NEW-SUFFIX
] [
    clear find/reverse tail FILE-ID "."
    return append FILE-ID NEW-SUFFIX
]

;;Uncomment to test
;NEW-ID: CHANGE-SUFFIX %testfilename-1.jpg ".png"
;print ["File name " NEW-ID " is of type " type? NEW-ID]
;NEW-ID: CHANGE-SUFFIX %testfilename-2.jpg %.png
;print ["File name " NEW-ID " is of type " type? NEW-ID]
;halt