文件名和文件夹的bat批量重命名替换关键字和删除关键字

文件名和文件夹的bat批量重命名替换关键字和删除关键字

批量文件名关键字替换

@echo off
set "str1=需要替换的关键字"
set "str2=替换后的关键字"
Setlocal Enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.*') do (
set "var=%%i" & ren "%%i" "!var:%str1%=%str2%!")

批量文件夹名关键字替换

@echo off
set "str1=需要替换的关键字"
set "str2=替换后的关键字"
Setlocal Enabledelayedexpansion
for /f "delims=" %%i in ('dir /a:d /b') do (
set "var=%%i" & ren "%%i" "!var:%str1%=%str2%!")

批量文件名关键字删除

@echo off
set "str=需要删除的字符串"
Setlocal Enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.*') do (
set "var=%%i" & ren "%%i" "!var:%str%=!")

批量文件夹名关键字删除

@echo off
set "str=需要删除的关键字"
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /a:d /b') do (
set "var=%%i" & ren "%%i" "!var:%str%=!")

你可能感兴趣的:(Windows小技巧,bat,批量重命名,删除关键字,替换关键字)