This button is an update and enhanced version of the original by @leo here.
Overview
Just select the folders* you want to merge and press the Merge Folders button to get the dialog. You'll be able to choose one of the selected folders as the target or create a new folder as the target.
*only ones in the same active tab will be merged

If you click the New button you'll be prompted to input a name for the new target folder. By default the name is the same as the first selected folder.

Once you click Ok, the job is done in the twinkling of an eye.
The old folders will be deleted at the end, as long as they are now empty. (They might not be empty if files in two folders had the same name and you chose to skip them.)
Download and install
- Merge Folders.english.dcf (9.4 KB)
- Merge Folders.french.dcf (11.3 KB)
Download Merge Folders.[your language].dcf above, then right click on a toolbar and select Customize... and drag the downloaded .dcf file to where you want the new button on your toolbar. Finally, click OK in the Customize window.
Changelog
[NEW] You can merge into one of the selected folders
[NEW] User friendly and fast action dialogs to allow multiple choice
[NEW] Dialog with a drop-down list of the selected folders
[FIX] Should be error proof now
Limitation
Currently, some features are missing such as:
- Merge to a folder that is elsewhere from the current tab.
- In flat view grouped mode, can not merge the selected subfolders, only the folders.
Note
If you want to improve this script, be my guest, post it in this thread and I will update this post.
Script Code
This is the code inside the download above, reproduced so you can see how the button works without downloading it:
' Console output function
' Sub Say(txt)
' 	DOpus.Create.Command.RunCommand("Say " & txt & "")
' End Sub
Function OnClick(ByRef ClickData)
	' INITIATE VARIABLES
	Match = 0
    Set cmd = ClickData.Func.command
	' Check the right kind of things are selected.
	If ClickData.Func.sourcetab.selected_dirs.count < 2 Then
		Set dlg = ClickData.Func.Dlg
		dlg.Request "2 folders at least are to be selected"  & vbCrLf & "Select serveral fodlers then run the command again", "OK"
		Exit Function
	End If
	If ClickData.Func.sourcetab.selected_files.count <> 0 Then
		Set dlg = ClickData.Func.Dlg
		dlg.Request "Only folders are to be selected."  & vbCrLf & "Unselect file(s) then run the command again", "OK"
		Exit Function
	End If
' 	DOpus.ClearOutput
	' Get the number of folder that are selected
	AllSel = ClickData.Func.sourcetab.selected_dirs.count
	' Concatenate all selected folders name to create a vector list
    Set SelDirCollection = DOpus.Create.Vector
	For Each SelDir In ClickData.Func.sourcetab.selected_dirs
        SelDirCollection.push_back SelDir.name
	Next
	' Create 1st Dialog object.
	Set dlg = DOpus.Dlg
	' Initialise the object to display a message with three buttons, one of which is a drop-down with multiple choices' This dialog also has a warning icon, a text field allowing the user to enter a line of text,' and two checkboxes which the user can turn on or off.
	dlg.window = DOpus.Listers(0)
	dlg.title = "Merge the " & AllSel & " selected folders"
	dlg.message = "Select existing target" & vbCrLf & "or create a new one with the last button below."
	dlg.buttons = "&OK|&Cancel|&New"
	dlg.icon = "question"
	dlg.sort = true
	dlg.choices = SelDirCollection
	dlg.selection = 0
	' Show the dialog and print the results to the script log
	ret = dlg.Show
' 	DOpus.Output "Dialog.Show returned " & ret
' 	DOpus.Output "The selected choice was " & dlg.choices(dlg.selection)
	If ret = 2 then ' When user cancel action
		Exit Function
	End If
	TargetDir = dlg.choices(dlg.selection)
    Set dlg = Nothing ' destroy 1st dialog prompt
	If (IsEmpty(TargetDir)) Then
        Set dlg = DOpus.Dlg
    	dlg.Request "ERROR : Target folder is invalid." & vbCrLf  & vbCrLf & "Nothing can't be done", "OK"
		Exit Function
	End If
	' When user want to create new target folder
	If ret = 0 Then
    	' Create 2nd Dialog object.
        Set dlg = DOpus.Dlg
		' Initialise the object to display a message with three buttons, one of which is a drop-down with multiple choices' This dialog also has a warning icon, a text field allowing the user to enter a line of text,' and two checkboxes which the user can turn on or off.
		dlg.Window = DOpus.Listers(0)
		dlg.title = "Merge the " & AllSel & " selected folders"
		dlg.message = "You can create a new folder below"
		dlg.buttons = "&OK|&Cancel"
		dlg.icon = "question"
        dlg.default = ClickData.Func.sourcetab.selected_dirs(0).name
		dlg.Select = True
		dlg.max = 128  ' enable the text field
		' Show the dialog and print the results to the script log
		ret = dlg.Show
' 		DOpus.Output "Dialog.Show returned " & ret
' 		DOpus.Output "The string you entered was " & dlg.input
		If ret = 0 then ' When user cancel action
			Exit Function
		End If
		TargetDir = dlg.input
    	Set dlg = Nothing ' destroy 2nd dialog prompt
		If (IsEmpty(TargetDir)) Then
			Set dlg = ClickData.Func.Dlg
	    	dlg.Request "You haven't input a name for new folder." & vbCrLf  & vbCrLf & "Nothing will be done", "OK"
			Exit Function
		End If
	End If
	' Handle the case the user want to move the files into one of the selected folder
	' Check if TargetDir matches one of the selected folder to avoid errors.
    For Each SelDir In ClickData.Func.sourcetab.selected_dirs
		If TargetDir = SelDir.name Then
			cmd.RemoveFile(SelDir) ' remove the dir from the collection so command won't apply to it
			Match = 1
			' Say("<white,red>STOP<black> : <dgreen>TargetDirEdited<black> = <red>SelDir : <white,red>" & SelDir.name & "")
		End If
	Next
	' Move everything from the selected folders into the new dir.
	If Match = 1 then ' Case when target folder matches a selected one
		' Say("<white,red>STOP<black> : <red>Match = " & Match & "")
		cmd.RunCommand "Copy MOVE ""{filepath$}\*"" TO=""{sourcepath$}\" & TargetDir & """"
	Else
		' Say("<white,dgreen>OK<black> : <dgreen>Match = " & Match & "")
		cmd.RunCommand "Copy MOVE ""{filepath$}\*"" TO=""{sourcepath$}"" CREATEFOLDER=""" & TargetDir & """"
	End If
	' Check each selected folder and, if it is now empty, delete it.
	cmd.ClearFiles
	For Each SelDir In ClickData.Func.sourcetab.selected_dirs
		Set FolderEnum = DOpus.FSUtil.ReadDir(SelDir, False)
		If (FolderEnum.Complete) Then
			FolderEnum.Close ' So the folder is not locked.
			cmd.AddFile SelDir
			cmd.RunCommand "Delete QUIET"
			cmd.ClearFiles
		End If
	Next
End Function

