Alternative version:
Button: Merge Folders v2 is an alternative version of this with slightly different behaviour.
Overview:
This gives you a button or hotkey which will merge folders together.
For example, you might start with this:
And end up with this:
Using the button:
Select two or more folders and click the button.
It will ask for the name of the new combined folder. By default, it uses the name of the first folder, with the last word removed.
Once you give a name, everything in the selected folders will be moved to the new folder. 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.dcf (3.69 KB)
Download Merge Folders.dcf (above), then go into Settings > Customize Toolbars mode and drag the .dcf file to where you want the new button on your toolbar. Finally, click OK in the Customize window.
Script code:
The script is provided here, as both text and screenshot, to help people browsing the forum for scripting techniques.
You don't need to do anything with this code if you just want to use the script. It's contained in the download above.
@script vbscript
Option Explicit
Function OnClick(ByRef ClickData)
Dim FirstDir, NewDir, NewDirEdited, SelDir, re, dlg, cmd, FolderEnum
Set dlg = ClickData.Func.Dlg
Set cmd = ClickData.Func.command
cmd.deselect = False
' Check the right kind of things are selected.
If ClickData.Func.sourcetab.selected_dirs.count < 2 Then
dlg.Request "At least two folders must be selected", "OK"
Exit Function
End If
If ClickData.Func.sourcetab.selected_files.count <> 0 Then
dlg.Request "Only folders should be be selected", "OK"
Exit Function
End If
' Run a regexp on the first dir's name, for the default new dir name.
FirstDir = ClickData.Func.sourcetab.selected_dirs(0).name
Set re = New RegExp
re.IgnoreCase = True
re.Global = False
re.Pattern = "^(.*) [^ ]+$" ' Strip the last word from the name.
If (re.Test(FirstDir)) Then
NewDir = re.Replace(FirstDir, "$1")
Else
NewDir = FirstDir
End If
' Ask the user what to call the new dir.
NewDirEdited = dlg.GetString("Enter new folder name", NewDir, 255, "OK|Cancel", "Merge folders")
If (IsEmpty(NewDirEdited)) Then
Exit Function
End If
' Move everything in the selected folders into the new dir.
cmd.RunCommand "Copy MOVE ""{filepath$}\*"" TO=""{sourcepath$}"" CREATEFOLDER=""" & NewDirEdited & """"
' 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