Categories

Filename Sanitizer

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

Character to replace illegal characters with

Remove leading and trailing whitespace

Remove leading and trailing dots (can cause issues in some systems)

Maximum filename length (0 = no limit, Windows typically limits to 255)

Key Facts

Category
Text Processing
Input Types
text, checkbox, number
Output Type
text
Sample Coverage
4
API Ready
Yes

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.

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.

Examples

1. Cleaning User-Uploaded Filenames

Web Developer
Background
A web application allows users to upload files, but some filenames contain illegal characters that cause issues on the server's file system.
Problem
Filenames with characters like : or * are not allowed on the server, leading to upload failures.
How to Use
Enter the problematic filename into the Filename Sanitizer, use default settings with underscore as the replacement character.
Outcome
The filename is cleaned, with illegal characters replaced by underscores, making it safe for storage and retrieval.

2. Preparing Files for Cross-Platform Deployment

Background
A software project needs to be deployed on both Windows and Linux servers, but filenames have OS-specific illegal characters.
Problem
Files with backslashes or colons in names fail on Linux systems, causing deployment errors.
How to Use
Use the tool to sanitize all filenames, setting a common replacement character and enabling trim options.
Example Config
Set replacementChar to '-', trimWhitespace to true, trimDots to true, maxLength to 255.
Outcome
All filenames are standardized and work seamlessly on both Windows and Linux, ensuring successful deployment.

Try with Samples

markdown, video, barcode

Related Hubs

FAQ

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.

API Documentation

Request Endpoint

POST /en/api/tools/filename-sanitizer

Request Parameters

Parameter Name Type Required Description
filename text Yes -
replacementChar text No Character to replace illegal characters with
trimWhitespace checkbox No Remove leading and trailing whitespace
trimDots checkbox No Remove leading and trailing dots (can cause issues in some systems)
maxLength number No Maximum filename length (0 = no limit, Windows typically limits to 255)

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-filename-sanitizer": {
      "name": "filename-sanitizer",
      "description": "Clean and sanitize filenames by removing illegal characters for Windows, Linux, and Mac",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=filename-sanitizer",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]