简体   繁体   English

窗口文件批处理从空格重命名为下划线

[英]Window File Batch Rename from Spaces to Underscore

I'm trying to use a batch to rename a file from "aaa aaa.doc" to "aaa_aaa.doc" 我正在尝试使用批处理将文件从“ aaa aaa.doc”重命名为“ aaa_aaa.doc”

I've written a script in the past to rename "aaa_aaa.doc" to "aaa aaa.doc" 我过去编写过一个脚本,将“ aaa_aaa.doc”重命名为“ aaa aaa.doc”

@echo off
setlocal enabledelayedexpansion
for %%a in (*_*) do (
  set file=%%a
  ren "!file!" "!file:_= !"
)

How to modify from " " to "_" and ignore special symbol? 如何从“”修改为“ _”并忽略特殊符号?

You've to reverse all steps and quote names with possible spaces. 您必须撤消所有步骤,并用可能的空格引用名称。

@echo off
setlocal enabledelayedexpansion
for %%a in ("* *") do (
  set "file=%%a"
  ren "%%a" "!file: =_!"
)

尝试这个!

ren "current_filename.ext" "new_filename.ext"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM