How to Exclude Files and Folders with croc: A Complete Guide

Use the --exclude flag for substring pattern matching or --exclude-file for exact path matching to filter out unwanted files and folders when sending data with croc.

When transferring directories with croc, you often need to skip temporary files, logs, or sensitive configuration files. The schollz/croc repository provides two complementary command-line flags that let you precisely control which files are omitted from the transfer without modifying your directory structure.

croc's Two File Exclusion Methods

croc implements two distinct filtering strategies in src/cli/cli.go that serve different exclusion needs during file transfers.

Exclude by Substring with --exclude

The --exclude flag performs case-insensitive substring matching against file paths. According to the source code in src/cli/cli.go (lines 79-80), this flag accepts comma-separated values that are split into the excludeStrings slice (lines 328-332). During the directory traversal (lines 499-518), croc checks if the file path contains any of these substrings and skips matching entries.

This method is ideal for filtering out file types or directories by name pattern. For example, excluding tmp will match temp, temporary, and /var/tmp/file.txt.

Exclude by Exact Path with --exclude-file

The --exclude-file flag requires an exact match with the relative path from the transfer root. Defined alongside --exclude in src/cli/cli.go (lines 79-80), these values populate the excludeFiles slice (lines 335-339). The comparison occurs at lines 511-518, ensuring only files matching the precise relative path are skipped from the transfer.

Use this approach when you need to exclude specific files like secret.txt or config.yaml without affecting other files that might contain similar substrings in their names.

How the Filtering Works Internally

The exclusion logic flows through three critical components of the codebase before files are transmitted.

In src/cli/cli.go, both exclusion slices are passed to the core transfer options at lines 373-374 when constructing the croc session. These options populate the Exclude and ExcludeFile fields in the Options struct defined in src/croc/croc.go.

The actual filtering implementation resides in src/utils/utils.go, specifically within the ZipDirectory helper function. At line 642, the code iterates over directory entries and skips any file that satisfies either exclusion rule before adding it to the transmission archive. The test suite in src/croc/croc_test.go validates this behavior to ensure excluded paths never appear in transmitted data.

Command-Line Examples

Use these practical examples to implement file exclusion in your croc transfers.

Exclude any path containing specific substrings:

croc send --exclude "tmp,.log,cache" /path/to/project

This command skips files like /path/to/project/tmp/data.txt and debug.log because their paths contain the excluded substrings.

Exclude specific files by exact relative path:

croc send --exclude-file "secret.txt,config.yaml" /path/to/project

This only skips secret.txt and config.yaml if they appear exactly at the root of the transferred directory structure.

Combine both flags for granular control:

croc send \
  --exclude "cache,thumb" \
  --exclude-file "notes.txt,debug.cfg" \
  /path/to/project

Using both flags together provides fine-grained control: substring matches catch whole groups of files, while exact matches let you drop individual items without affecting similarly named files in subdirectories.

Summary

  • croc provides two exclusion flags: --exclude for substring matching and --exclude-file for exact path matching.
  • Flag parsing occurs in src/cli/cli.go (lines 79-80), where comma-separated values split into excludeStrings and excludeFiles slices (lines 328-339).
  • The exclusion logic executes in src/utils/utils.go within the ZipDirectory function (line 642) before files enter the transmission archive.
  • Both filters are passed to the Options struct in src/croc/croc.go (lines 373-374) and can be combined for precise file filtering during transfers.

Frequently Asked Questions

What is the difference between --exclude and --exclude-file in croc?

The --exclude flag filters files whose paths contain the specified substrings anywhere in the filename or directory structure, while --exclude-file requires an exact match with the relative path from the transfer root. Use --exclude to block entire categories of files (like all .log files) and --exclude-file to remove specific individual files without affecting other files with similar names.

Can I use multiple exclusion patterns in a single croc command?

Yes. Both flags accept comma-separated values without spaces. For example, --exclude "tmp,cache,.git" excludes any path containing "tmp", "cache", or ".git". You can also combine both flags simultaneously to apply both substring and exact-match filters to the same transfer operation.

Does croc's file exclusion work with folder names?

Yes. The --exclude flag matches substrings within any part of the path, so excluding a folder name like node_modules will skip the entire directory and all its contents recursively. The --exclude-file flag can also exclude folders if you specify the exact relative path to the directory you want to omit.

Where is the exclusion logic implemented in the croc source code?

The exclusion flags are defined and parsed in src/cli/cli.go (lines 79-80), stored in the Options struct in src/croc/croc.go, and enforced during the directory zipping process in src/utils/utils.go at line 642. The test suite in src/croc/croc_test.go validates this behavior to ensure excluded paths never appear in transmitted archives.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →