Batch File to replace underscores with spaces in a filename

前端 未结 1 1449
自闭症患者
自闭症患者 2021-01-21 16:26

I am trying to replace underscores in some file names with spaces, for example:

this_is_a_file.pdf

becomes:

this is a file.pdf         


        
相关标签:
1条回答
  • 2021-01-21 16:48

    Use %file:_= % to represent %file% with underscores replaced with spaces. Unfortunately this won't work on a for variable so if you're looping over files you have to use an intermediate variable.

    @echo off
    setlocal enabledelayedexpansion
    for %%a in (*_*) do (
      set file=%%a
      ren "!file!" "!file:_= !"
    )
    
    0 讨论(0)
提交回复
热议问题