Skip to content

Instantly share code, notes, and snippets.

@jkonrath
Created June 3, 2021 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkonrath/fb471f4d15947555af254c877ca04d53 to your computer and use it in GitHub Desktop.
Save jkonrath/fb471f4d15947555af254c877ca04d53 to your computer and use it in GitHub Desktop.
Windows CMD underscores to dashes
@echo off
rem Go through every file in a directory and replace _ with - in each filename.
rem I'm sure I pasted this from somewhere, no idea.
rem I wouldn't have to do this if people stopped using underscores in filenames.
rem It's bad SEO, and it's that much more typing. Just stop it.
Setlocal enabledelayedexpansion
rem You could change these two to replace any string with another.
Set "Pattern=_"
Set "Replace=-"
For %%a in (*.*) Do (
Set "File=%%~a"
Ren "%%a" "!File:%Pattern%=%Replace%!"
)
Pause&Exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment