How to replace all spaces by underscores in all file names of a folder?

后端 未结 8 2300
鱼传尺愫
鱼传尺愫 2020-12-07 18:50

I\'m trying to rename all the files inside a folder (all .exe files). I want to replace all the spaces with underscores, e.g. qwe qwe qwe asd.exe to qwe_q

8条回答
  •  遥遥无期
    2020-12-07 19:44

    Adapted from here:

    https://stackoverflow.com/a/16129486/2000557

    @echo off
    Setlocal enabledelayedexpansion
    
    Set "Pattern= "
    Set "Replace=_"
    
    For %%a in (*.exe) Do (
        Set "File=%%~a"
        Ren "%%a" "!File:%Pattern%=%Replace%!"
    )
    
    Pause&Exit
    

    Create a batch file (*.bat) with the above contents. Place that batch file in the folder with all the .exe's and it will replace the spaces with underscores when you run it.

提交回复
热议问题