1
0
Fork
You've already forked dirmerge
0
Tool for merging directories.
  • OCaml 98.5%
  • Makefile 1.5%
2026年04月20日 19:54:25 +02:00
cli.ml New cli switch -c to create target dir if not existing. 2026年04月20日 19:54:25 +02:00
dir.ml printing infos now only with verbosity-switch 2024年08月06日 02:01:34 +02:00
dir.mli printing infos now only with verbosity-switch 2024年08月06日 02:01:34 +02:00
LICENSE Initial public commit. 2024年06月13日 03:49:17 +02:00
main.ml New cli switch -c to create target dir if not existing. 2026年04月20日 19:54:25 +02:00
Makefile Initial public commit. 2024年06月13日 03:49:17 +02:00
merge.ml Initial public commit. 2024年06月13日 03:49:17 +02:00
merge.mli Initial public commit. 2024年06月13日 03:49:17 +02:00
names.ml Initial public commit. 2024年06月13日 03:49:17 +02:00
OCamlMakefile Initial public commit. 2024年06月13日 03:49:17 +02:00
README.md New cli switch -c to create target dir if not existing. 2026年04月20日 19:54:25 +02:00
tools.ml printing infos now only with verbosity-switch 2024年08月06日 02:01:34 +02:00

Dirmerge - a Tool to Merge Directories

Purpose of this tool is to merge directories.

The tool dirmerge gets at least two command line arguments. The first argument is the target directory, the second argument is the source directory.

It is (currently) possible to give up to 8 source directories. The merge operation megres all source directories with the target directory.

In case of name clashes, all name-clashing entities will be renamed so that the merge can happen without losing contents and without leaving directories unmerged. The new names will be longer than the original names, so it must be guaranteed, that no files exist in target and source directories, that are too long to be allowed by the used filesystem. (The responsibility of the user). The length of the new names are longer than all files that reside in the directories to be merged.

The new names are derived from the clashing names by adding a number (one digit, 1 ... 9) at the end of the basenames (before the extension), with enough underlines leading that number, so that the new names will be long enough not to conflict with any pre-existing files in the merged directories.

Recursive operation is not implemented.

Two ways of Merging

  • default: move the contents of the source directories into the target directory
  • directly: move the source directories directly into the target directory (-d switch)

All source directories will be removed after the merge. For the direct merge this seems to be obvious (it is like using 'mv' to move the directories). In case of the default merge, when the contents of the source directories is moved into the target directory, the source directories would be left over empty if not removed, so removing the empty directories by dirmerge seems to be a reasonable decision.

Merge or just print 'mv' commands

The full functionality of automatic merges is only possible on the same filesystem. Merges across different filesystems are not possible.

But the command line option -a allows merges across filesystems indirectly, by printing mv commands, which the user then can apply for the across-fs-merge.

In case of a default merge (no -d switch), the rmdir commands for removing the source directories will also be printed.

Usage

$ dirmerge [ option-switches ] <target_dir> <srcdir_1> [ ... <srcdir_n> ] # with n = 2, 3, ..., 8

Option Switches

  • -d directly insert the whole source-directories into the target directory (instead of the contents of the source directories)
  • -a accross filesystems: instead of performing merging actions, print mv and rmdir commands, which allows merging across filesystems
  • -c if the target directory does not exist, this switch creates it (permissions: rwx for user only)
  • -v verbose: print messages to the user about the actions performed (in default mode)

Possible Problems

It must be guaranteed that the filenames (in target and all source directories) are short enough, so that the resulting filenames (which will be longer than the longest existing filenames of these directories) are allowed in the filesystem. If this condition is not met, data loss might be possible.

Of course the user of dirmerge must have the permission to rename, move and remove files and directories for all directories used as command line arguments to dirmerge.

Build / Install

This program can be build with OCaml 4.x as programming language. No external libraries are used.

With OCaml installed on your system, to build dirmerge, just type make from within this repo directory.

There is no installation script. Just copy dirmerge to your $HOME/bin/ directory.

Disclaimer

Use this tool at your own risk. Best care has been used to provide a program that does not result in data loss, but this can't be guaranteed. See section 'Possible Problems'.