* _replaceext, version 1.0
* 26 Oct 2017
* Doug Hemken, Social Science Computing Cooperative

/* Note:  this breaks where a sub-folder name contains
a period, but there is no file extension
*/

program define _replaceext, rclass
	syntax using/, new(string)

	_fileext using "`using'"
	if "`r(extension)'" ~= "" {
		local newfile: subinstr local using "`r(extension)'" "`new'"
		}
		else {
		local newfile "`using'.`new'"
		}

	return local newfile "`newfile'"

end