{"id":16978,"library":"dir-compare-cli","title":"Directory Compare CLI","description":"dir-compare-cli is a command-line interface (CLI) utility built for Node.js that enables users to compare the contents of two directories. It functions as a wrapper around the `dir-compare` library, providing a convenient console interface for directory comparison tasks. Currently stable at version 1.0.1, its release cadence is generally tied to updates and maintenance of its underlying library or when specific CLI-focused enhancements are required. Key differentiators include its robust set of comparison options, allowing comparisons by file size (default), content, modification date, and symlink targets. It also supports powerful file and directory filtering using Minimatch glob patterns, and offers detailed reporting capabilities including CSV output and distinct exit codes for scripting automation.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/gliviu/dir-compare-cli","tags":["javascript","compare","directory","folder","cli"],"install":[{"cmd":"npm install dir-compare-cli","lang":"bash","label":"npm"},{"cmd":"yarn add dir-compare-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add dir-compare-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This CLI acts as a wrapper for the `dir-compare` library, which performs the core directory comparison logic.","package":"dir-compare","optional":false}],"imports":[],"quickstart":{"code":"# Install globally to make the 'dircompare' command available\nnpm install -g dir-compare-cli\n\n# Create some dummy directories and files for demonstration\nmkdir -p dir1/subdir\necho \"Hello from file1\" > dir1/file1.txt\necho \"Hello from file2\" > dir1/subdir/file2.js\n\nmkdir -p dir2/subdir\necho \"Hello from file1\" > dir2/file1.txt\necho \"Modified content\" > dir2/subdir/file2.js\necho \"New file\" > dir2/new_file.txt\n\n# Compare dir1 and dir2 by content, showing only distinct entries\n# and include the reason for distinction.\n# Exit code 1 indicates differences were found.\ndircompare -c -d --reason dir1 dir2\n\n# Clean up dummy directories\nrm -rf dir1 dir2","lang":"javascript","description":"This example demonstrates how to install the CLI globally and then use it to compare two directories by content, explicitly showing only distinct files and the reason for their differences."},"warnings":[{"fix":"Always add `-c` or `--compare-content` to your command for content-based comparisons: `dircompare -c dir1 dir2`.","message":"By default, `dircompare` only compares files by size. To ensure a thorough comparison, especially for identifying subtle changes, always explicitly use the `-c` or `--compare-content` flag.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"In shell scripts, check the `$?` variable (or equivalent) after execution: `dircompare dir1 dir2; if [ $? -eq 1 ]; then echo 'Directories are different.'; fi`.","message":"The CLI uses specific exit codes: `0` for identical directories, `1` for distinct directories, and `2` for errors. Scripts relying on `dircompare` should always check these exit codes for proper control flow.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For stricter date comparison, set `--date-tolerance` to `0` or a very small value: `dircompare -D --date-tolerance 0 dir1 dir2`.","message":"When comparing by date using `-D`, the `--date-tolerance` flag defaults to `1000` milliseconds (1 second). Files with modification dates differing by less than this tolerance will be considered identical. This can lead to false positives if precision is critical.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult the Minimatch documentation for correct glob pattern syntax. Use relative paths for filters, e.g., `dircompare -x \"**/node_modules\" dir1 dir2`.","message":"Filter and exclude patterns (`-f`, `-x`) utilize Minimatch glob patterns, which match against the *relative path* of entries. Absolute paths or incorrect pattern syntax can lead to unexpected filtering results.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Install the package globally using `npm install -g dir-compare-cli` to make the `dircompare` command available in your system's PATH.","cause":"The `dir-compare-cli` package was installed locally or not installed globally.","error":"dircompare: command not found"},{"fix":"Verify that both directory paths provided to `dircompare` are correct and exist on your filesystem. Use absolute paths or ensure you are running the command from the correct working directory.","cause":"One of the provided directory paths (`leftdir` or `rightdir`) does not exist or is misspelled.","error":"Error: ENOENT: no such file or directory, stat 'leftdir'"},{"fix":"Review the command options. Add `-a` or `--show-all` to see a detailed report of all entries and their differences. Explicitly use `-c` for content comparison, `-D` for date, or check for filters that might be excluding relevant files.","cause":"The default comparison mode (by file size) might find differences even if content is identical, or vice-versa. Or, other criteria like dates or symlinks might differ.","error":"Exit code 1, but I expected identical directories."}],"ecosystem":"npm","meta_description":null}