如何在Windows替换使用批处理子重命名文件 [英] How to rename file by replacing substring using batch in Windows

查看:144
本文介绍了如何在Windows替换使用批处理子重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重命名的文件名一样的如何于─改名 -file.jpg的到的如何于─再利用 -file.jpg的使用Windows批处理文件

即。我只希望在一个文件名来替换一个或两个词。


解决方案

 关闭@echo设置文件名=如何对重命名,file.jpg
设置模式=重命名
设置替换=重用REM呼叫重命名%FILENAME%%%文件名:%格局%=%替换%%%通话回音%%文件名:%格局%=%替换%%%
::结果:怎么到重用file.jpg暂停和放大器;退出

我给你的文件的一个循环其他例如:


  

更新:


我已经错过了在语法因为快速打字我最后一次编辑一些东西,这里是修正code:

 关闭@echo
SETLOCAL enabledelayedexpansion设置模式=重命名
设置替换=重用对于%%#中(C:\\文件夹\\ *。JPG),DO(
    设置文件= %%〜NX#
    仁%%#文件:%图案%=%替换%!
)暂停和放大器;退出

PS:你可以在这里阅读,以了解更多关于子:
http://ss64.com/nt/syntax-substring.html
http://ss64.com/nt/syntax-replace.html

I want to rename file name like "how-to-rename-file.jpg" to "how-to-reuse-file.jpg" by using a Windows batch file

I.e. I only want to replace one or two words in a file name.

解决方案

@echo off

Set "Filename=how-to-rename-file.jpg"
Set "Pattern=rename"
Set "Replace=reuse"

REM Call Rename "%Filename%" "%%Filename:%Pattern%=%Replace%%%"

Call Echo %%Filename:%Pattern%=%Replace%%%
:: Result: how-to-reuse-file.jpg

Pause&Exit

I give you other example for a loop of files:

UPDATE:

I've missed some things in the syntax 'cause fast-typing my last edit, here is the corrected code:

@echo off
Setlocal enabledelayedexpansion

Set "Pattern=rename"
Set "Replace=reuse"

For %%# in ("C:\Folder\*.jpg") Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%Pattern%=%Replace%!"
)

Pause&Exit

PS: You can read here to learn more about substring: http://ss64.com/nt/syntax-substring.html http://ss64.com/nt/syntax-replace.html

这篇关于如何在Windows替换使用批处理子重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆