Rename.Tools LogoRename.Tools
FeaturesGuidesApp
RRename.Tools

A powerful browser-based bulk file renaming tool. Supports regex, rule chains, live preview — all processing done locally with complete privacy.

Local file processing · No file uploads

Legal

  • Terms of Service
  • Privacy Policy
  • Disclaimer

Resources

  • About
  • All Features
  • Guides
  • GitHub
  • Report an Issue
  • Changelog

Languages

  • English
  • 中文
  • 日本語
  • Español
  • Français
  • 한국어
  • Deutsch

© 2026 Rename.Tools. All rights reserved.

Made with by developers

Back to guides

Everyday tasks

Replace Spaces in Filenames with Underscores or Hyphens

Normalize separators before sharing a folder or using filenames in a project. Choose whether each space becomes an underscore, a hyphen or nothing, then check repeated spaces and naming collisions before applying the change.

Replace spaces with underscores

Before
Quarterly Report 2026.pdf
After
Quarterly_Report_2026.pdf
Before
draft final.txt
After
draft__final.txt

Replaces every ordinary space with an underscore. Two consecutive spaces become two underscores; other punctuation and extensions are unchanged.

Try this example

Review the rules, then preview sample filenames without changing real files.

Rename.Tools5 min readUpdated 2026-09-21

Replace every ordinary space with an underscore

Use Find & Replace for a literal space. The Find field contains one press of the space bar, not the word space or the two characters \s. Enable Replace all to change every occurrence.

The Try this example button opens this exact rule. Confirm Try with sample filenames to see both a normal name and a name containing two consecutive spaces. No file access is needed for this test.

  1. 1Set Scope to Name so extensions remain unchanged.
  2. 2Add Find & Replace. Enter one ordinary space in Find and _ in Replace with.
  3. 3Enable Replace all and leave By position off.
  4. 4Check the preview. Two spaces become two underscores because this is a character-for-character replacement.
Quarterly Report 2026.pdfQuarterly_Report_2026.pdf
draft final.txtdraft__final.txt

Choose hyphens or remove spaces entirely

For hyphens, change Replace with to -. To remove ordinary spaces, leave Replace with empty. Neither setting changes the letter case or other punctuation.

Removing separators can make names harder to read: My Report becomes MyReport. Keep the distinction between replacing spaces and converting to snake_case; case conversion can also split words and change existing separators.

My Report.pdfMy-Report.pdf

Find one ordinary space; replace all with -.

My Report.pdfMyReport.pdf

Find one ordinary space; replace all with empty text.

Collapse repeated whitespace with regex

If you want several consecutive whitespace characters to become one separator, use Regex Replace instead of the literal rule: pattern \s+, replacement _, flags g. It matches whitespace runs, including tabs where the filesystem permits them.

A leading or trailing run also becomes an underscore. To remove surrounding whitespace first, put a separate Regex Replace rule before it: pattern ^\s+|\s+$, empty replacement, flags g. This trimming step is optional and is not included in the basic example button.

draft final.txtdraft_final.txt

Only Regex Replace: \s+ → _, flags g.

My Report .pdfMy_Report.pdf

First trim ^\s+|\s+$ with empty replacement and flags g, then \s+ → _ with flags g.

Review collisions and mixed naming styles

Report Final.pdf and Report_Final.pdf both end up as Report_Final.pdf when spaces become underscores. Select a different label, exclude one file, or resolve the conflict in the preview before executing. Collapsing whitespace can create similar collisions.

This cleanup changes filenames, not folder names or document contents. A Name-scoped rule preserves .pdf and other extensions; it does not convert file formats. Existing references to old filenames may need updating.

After testing, clear the sample list and import your real files in a supported desktop browser such as Chrome or Edge. Review the complete batch and execute only when the names are correct. If direct file access is unavailable, use sample names to generate a script, review it, and run it in the corresponding folder.

Related guides

Add a Prefix or Suffix to Multiple FilenamesBulk Rename Files with Regex: Examples & PatternsBulk file renaming basics: import, preview, execute

Ready to try the workflow?

Open Rename.Tools, add a few sample files, and preview every rule before touching the real filenames.

Try this example