Please try this new version:
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Duplicate Template Folder</label>
<icon1>#default:newcollection</icon1>
<function type="script">
<instruction>option explicit</instruction>
<instruction />
<instruction>Function ZeroPad(str, slen)</instruction>
<instruction> str = CStr(Str) ' Force To String.</instruction>
<instruction> If (Len(str) < slen) Then</instruction>
<instruction> str = String(slen - Len(str), "0") & str</instruction>
<instruction> End If</instruction>
<instruction> ZeroPad = str</instruction>
<instruction>End Function</instruction>
<instruction />
<instruction>Function IsLongInteger(str)</instruction>
<instruction> IsLongInteger = False</instruction>
<instruction> If (IsNumeric(str)) Then</instruction>
<instruction> ' Not really needed, but make sure the number doesn't have a decimal point.</instruction>
<instruction> If (CStr(CLng(str)) = CStr(str)) Then</instruction>
<instruction> IsLongInteger = True</instruction>
<instruction> End If</instruction>
<instruction> End If</instruction>
<instruction>End Function</instruction>
<instruction />
<instruction>Function OnClick(ClickData)</instruction>
<instruction> Dim dlgTitle, tab, dlg, cmd, numFolders, regexp, matches</instruction>
<instruction> Dim fullName, namePrefix, nameSuffix, prefixLen, nowDate, i</instruction>
<instruction> Dim fsu, folderEnum, currentPrefix, currentPath, currentItem</instruction>
<instruction> Dim origName, origNameUpper, origNameUpperDot, origNameUpperLen, testUpper</instruction>
<instruction> dlgTitle = "Duplicate template folder"</instruction>
<instruction> nowDate = Date()</instruction>
<instruction> Set tab = Clickdata.func.sourcetab</instruction>
<instruction> Set dlg = ClickData.func.Dlg</instruction>
<instruction> Set cmd = ClickData.func.command</instruction>
<instruction> Set regexp = New RegExp</instruction>
<instruction> Set fsu = DOpus.FSUtil</instruction>
<instruction />
<instruction> cmd.deselect = False</instruction>
<instruction />
<instruction> ' Check exactly one folder is selected.</instruction>
<instruction />
<instruction> If (tab.selected_dirs.count <> 1 Or tab.selected_files.count <> 0) Then</instruction>
<instruction> dlg.Request "Select one folder to duplicate.", "OK", dlgTitle</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> origName = tab.selected_dirs(0).name</instruction>
<instruction />
<instruction> ' Split the folder name up to take the counter from the start.</instruction>
<instruction />
<instruction> regexp.IgnoreCase = True</instruction>
<instruction> regexp.Global = True</instruction>
<instruction> regexp.Pattern = "^(\d+)_(.+)$"</instruction>
<instruction> Set matches = regexp.Execute(origName)</instruction>
<instruction> If (matches.count < 1) Then</instruction>
<instruction> dlg.Request "Selected folder's name does not fit the expected pattern.", "OK", dlgTitle</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> namePrefix = matches(0).SubMatches(0)</instruction>
<instruction> nameSuffix = matches(0).SubMatches(1)</instruction>
<instruction />
<instruction> prefixLen = Len(namePrefix)</instruction>
<instruction> namePrefix = CLng(namePrefix)</instruction>
<instruction />
<instruction> ' Ask how many copies to make.</instruction>
<instruction />
<instruction> dlg.Select = True</instruction>
<instruction> dlg.default = "1" ' Default number of folders to create</instruction>
<instruction> dlg.max = 4 ' Max string length. More than 9999 folders would probably be a mistake.</instruction>
<instruction> dlg.buttons = "OK|Cancel"</instruction>
<instruction> dlg.message = "Number of folders to create:"</instruction>
<instruction> dlg.title = dlgTitle</instruction>
<instruction> If (dlg.Show() <> 1) Then</instruction>
<instruction> Exit Function ' Cancelled</instruction>
<instruction> End If</instruction>
<instruction> numFolders = dlg.Input</instruction>
<instruction />
<instruction> If (Not IsLongInteger(numFolders)) Then</instruction>
<instruction> dlg.Request "Invalid number of folders entered.", "OK", dlgTitle</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> numFolders = CLng(numFolders)</instruction>
<instruction />
<instruction> ' Ask for the new name.</instruction>
<instruction />
<instruction> dlg.Select = False</instruction>
<instruction> dlg.default = nameSuffix</instruction>
<instruction> dlg.max = 255</instruction>
<instruction> dlg.buttons = "OK|Cancel"</instruction>
<instruction> dlg.message = "Name for the new folders (number will be prefixed automatically):"</instruction>
<instruction> dlg.title = dlgTitle</instruction>
<instruction> If (dlg.Show() <> 1) Then</instruction>
<instruction> Exit Function ' Cancelled</instruction>
<instruction> End If</instruction>
<instruction> nameSuffix = "_" & Trim(dlg.Input)</instruction>
<instruction />
<instruction> If nameSuffix = "_" Then</instruction>
<instruction> dlg.Request "No folder name given.", "OK", dlgTitle</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> ' Warn if any prefix numbers in the range we are about to create are already in use.</instruction>
<instruction> </instruction>
<instruction> Set folderEnum = fsu.ReadDir(Clickdata.func.sourcetab.path, False)</instruction>
<instruction> Do While Not folderEnum.Complete</instruction>
<instruction> Set matches = regexp.Execute(folderEnum.Next.name)</instruction>
<instruction> If (matches.count > 0) Then</instruction>
<instruction> currentPrefix = CLng(matches(0).SubMatches(0))</instruction>
<instruction> If (currentPrefix >= (namePrefix + 1)) Then</instruction>
<instruction> If (dlg.Request("Folders already exist with prefix " & (namePrefix + 1) & " or above." & vbCrLf & "Are you sure you wish to continue?", "Continue|Cancel", dlgTitle) <> 1) Then</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction> Exit Do</instruction>
<instruction> End If</instruction>
<instruction> End If</instruction>
<instruction> Loop</instruction>
<instruction />
<instruction> ' Create the duplicate folders</instruction>
<instruction />
<instruction> currentPrefix = namePrefix</instruction>
<instruction />
<instruction> origNameUpper = UCase(origName)</instruction>
<instruction> origNameUpperDot = origNameUpper & "."</instruction>
<instruction> origNameUpperLen = Len(origNameUpper)</instruction>
<instruction />
<instruction> For i = 1 To numFolders</instruction>
<instruction> currentPrefix = currentPrefix + 1</instruction>
<instruction> fullName = ZeroPad(currentPrefix, prefixLen) & nameSuffix</instruction>
<instruction> cmd.RunCommand "Copy DUPLICATE HERE AS=""" & fullName & """"</instruction>
<instruction />
<instruction> ' Rename files below the folder to use the new name, if they were using the old name.</instruction>
<instruction> currentPath = Clickdata.func.sourcetab.path & "\" & fullName</instruction>
<instruction> Set folderEnum = fsu.ReadDir(currentPath, False)</instruction>
<instruction> Do While Not folderEnum.Complete</instruction>
<instruction> Set currentItem = folderEnum.Next</instruction>
<instruction> testUpper = UCase(currentItem.name)</instruction>
<instruction> If (testUpper = origNameUpper Or Left(testUpper,origNameUpperLen+1) = origNameUpperDot) Then</instruction>
<instruction> cmd.RunCommand "Rename FROM=""" & currentItem.realPath & """ TO=""" & fullName & Mid(currentItem.name,origNameUpperLen+1) & """"</instruction>
<instruction> End If</instruction>
<instruction> Loop</instruction>
<instruction> Next</instruction>
<instruction />
<instruction> ' Select what was created</instruction>
<instruction />
<instruction> cmd.RunCommand "Select NONE"</instruction>
<instruction />
<instruction> currentPrefix = namePrefix</instruction>
<instruction />
<instruction> For i = 1 To numFolders</instruction>
<instruction> currentPrefix = currentPrefix + 1</instruction>
<instruction> fullName = ZeroPad(currentPrefix, prefixLen) & nameSuffix</instruction>
<instruction> cmd.RunCommand "Select MAKEVISIBLE EXACT PATTERN=""" & fullName & """"</instruction>
<instruction> Next</instruction>
<instruction />
<instruction>End Function</instruction>
</function>
</button>
It will ask how many folders to create, as before, and will then ask for the name of the new folders.
The name you see/type doesn't include the counter. So if you're duplicating "1514_72up_051214" it will show you "72up_051214" which you can then edit, and it will add the number back on the front before making the folders.
After it makes the duplicate folders, it will look in them for any files which had the same names as the old folder (ignoring the file extension part), and rename them to match the new folder name.
I didn't restrict the renaming to just .aep and .xls files, but could do that if needed. It will work with anything that is either exactly the same as the old directory name (without an extension), or is the old directory name plus a dot, plus anything else after the dot.