Batch File to replace underscores with spaces in a filename

隐身守侯 提交于 2019-12-02 05:46:59

问题


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

In Windows using a batch file.

I have found a similar question, but it replaces spaces with nothing: How to remove spaces from file names (in bulk)

Can it be easily translated to do what I want?


回答1:


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:_= !"
)


来源:https://stackoverflow.com/questions/14387780/batch-file-to-replace-underscores-with-spaces-in-a-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!