BomSweeper is a command-line tool that finds the files starting with a UTF-8 Byte Order Mark (BOM) in the directory tree and removes BOMs from those files.

Get started

BomSweeper is available as the NuGet-logo NuGet package, so it can be installed as follows:

dotnet tool install -g BomSweeper.GlobalTool

Synopsis

bomsweeper [-C DIR] [-D N] [-RVhv] [--] PATTERN...

Description

The PATTERN arguments represent the glob patterns that match the paths of the files to find.

The path separator in the pattern must be a slash ('/') character regardless of the platform. The directory names . and .. in the pattern are not interpreted specially (that is, . and .. do not mean the current and parent directory, respectively). So, for example, the pattern foo/../bar/baz.cs does not match bar/baz.cs.

Note that the pattern matching is performed with the relative paths to the current directory, so if the pattern starts with a slash, it does not match any file.

The pattern can contain an asterisk ('*') character as a wildcard, which matches any character other than a slash zero or more times. It can also contain a double asterisk ('**'), which represents as follows:

  • if the pattern equals **, it matches all files in the current directory and in its subdirectories.

  • if the pattern ends with /** (a slash followed by a double asterisk), the subpattern /** matches all files in the directory and subdirectories.

  • if the pattern starts with **/ (a double asterisk followed by a slash), the subpattern **/ matches the current directory and its subdirectories. For example, **/foo matches foo, bar/foo, and bar/baz/foo.

  • if the pattern contains /**/, the subpattern /**/ matches a slash, the directories, and subdirectories. For example, foo/**/bar matches foo/bar, foo/baz/bar, and foo/baz/qux/bar.

Options are as follows:

| | Option | | Description | |---:|:---|:---|:---| | -C, | --directory | DIR | Change to directory. (Default: .) | | -h, | --help | | Show help message and exit | | -D, | --max-depth | N | The maximum number of directory levels to search. (Default: 16) | | -R, | --remove | | Remove a BOM | | -v, | --verbose | | Be verbose | | -V, | --version | | Show version and exit |

Exit status

BomSweeper exits 0 if no files starting with a UTF-8 BOM are found, and >0 if one or more files are found or if an error occurs.

When the -R or --remove option is specified, it exits 0 on success, and >0 if an error occurs.

Example

Note that, in the following examples, the glob pattern is enclosed in apostrophes ('...') to prevent the shell from expanding the pattern.

bomsweeper '**/*.cs'

Find .cs files starting with a UTF-8 BOM in the current directory and subdirectories.

bomsweeper -R '**/*.cs'

Find .cs files in the current directory and subdirectories, and remove a UTF-8 BOM from the files if any.

Documents

How to contribute

Please send us pull requests or issues from the GitHub icon GitHub repository.