Does this help?
You’s have to replace the line
alert (theFiles.join("\n"))
with the proper operations.
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i);
alert (theFiles.join("\n"))
};