# Filename Sanitizer

Clean and sanitize filenames by removing illegal characters for Windows, Linux, and Mac

> Canonical page: https://elysiatools.com/en/tools/filename-sanitizer

- **Category:** Text Processing

- **Keywords:** filename, sanitizer, clean, illegal, windows, linux, mac, safe, Filename Sanitizer

## Overview

The Filename Sanitizer is a utility tool that cleans and sanitizes filenames by removing illegal characters for Windows, Linux, and Mac, ensuring compatibility and preventing file system errors across different operating systems.

## Inputs

- **Filename** (text): Enter filename to sanitize...
- **Replacement Character** (text): Character to replace illegal characters with
- **Trim Whitespace** (checkbox): Remove leading and trailing whitespace
- **Trim Leading/Trailing Dots** (checkbox): Remove leading and trailing dots (can cause issues in some systems)
- **Maximum Length** (number): Maximum filename length (0 = no limit, Windows typically limits to 255)

## When to use

- When you have filenames with special characters that are not allowed on certain operating systems, such as Windows or Linux.
- When preparing files for cross-platform sharing or deployment to avoid compatibility issues.
- When batch processing filenames to ensure they meet system requirements and prevent errors during file operations.

## How it works

- Input the filename you want to sanitize into the tool's text field.
- Optionally specify a replacement character for illegal characters, with underscore as the default.
- Choose to trim leading/trailing whitespace and dots, and set a maximum filename length if needed.
- The tool processes the input and outputs a sanitized filename with illegal characters replaced or removed.

## Use cases

- Sanitizing filenames uploaded by users on a web application to ensure they are stored safely on the server.
- Preparing filenames for use in automated scripts that run on multiple operating systems like Windows and Linux.
- Cleaning up filenames in a directory to avoid errors when moving or copying files across different systems.

## Frequently asked questions

### What illegal characters does this tool remove?

It removes characters like < > : " / \ | ? * and control characters for Windows, and / and null characters for Linux/Mac.

### Can I customize the replacement character?

Yes, you can specify any character to replace illegal ones, with underscore as the default.

### Does it handle whitespace trimming?

Yes, you can enable trimming of leading and trailing whitespace, which is on by default.

### What is the maximum filename length supported?

The default maximum is 255 characters, but you can set it from 0 (no limit) to 260.

### Is this tool free to use?

Yes, the Filename Sanitizer is a free online tool for cleaning filenames.

## Related tools

- [Number Format Cleaner](https://elysiatools.com/en/tools/number-format-cleaner): Normalize and clean various number formats in text for consistency
- [Markdown to Plain Text](https://elysiatools.com/en/tools/markdown-to-plain-text): Convert Markdown formatted text to plain text by removing all Markdown syntax and formatting
- [Remove Duplicate Lines](https://elysiatools.com/en/tools/remove-duplicate-lines): Deduplicate lines in a list or text block. Keep the first or last occurrence, with options for case sensitivity, whitespace trimming, and dropping empty lines.
- [Array Element Deleter](https://elysiatools.com/en/tools/array-element-deleter): Delete specific elements from arrays with support for multiple deletion methods
- [Text Compressor](https://elysiatools.com/en/tools/text-compressor): Compress text by removing extra spaces, newlines, and unnecessary whitespace while preserving content structure
- [Whitespace Normalizer](https://elysiatools.com/en/tools/whitespace-normalizer): Replace consecutive spaces/tabs with single space and trim line start/end whitespace
- [HTML Tag Stripper](https://elysiatools.com/en/tools/html-tag-stripper): Remove HTML tags and extract clean text content
- [Trimmed Mean Calculator](https://elysiatools.com/en/tools/trimmed-mean-calculator): Calculate a trimmed mean by removing the same percentage of low and high values before averaging

## Samples

- [Illegal Filename Samples](https://elysiatools.com/en/samples/filename-illegal-characters-samples): Sample filenames with illegal characters, reserved names, and cross-platform issues for testing filename sanitization
- [Regex Replace Samples](https://elysiatools.com/en/samples/regex-replace): Collection of common and useful regex replacement patterns for text transformation and data cleaning
- [Windows File Operations - C++ Samples](https://elysiatools.com/en/samples/windows-file-operations-cpp): Comprehensive C++ file operations examples for Windows platform including text file I/O, file copying, and directory traversal
- [Windows File Operations - C# Samples](https://elysiatools.com/en/samples/windows-file-operations-csharp): Comprehensive C# file operations examples for Windows platform including text file I/O, file copying, directory traversal, and file system operations
