文章目录
- linux 批量重命名
- Windows 批量重命名
- 参考资料
linux 批量重命名
示例脚本–将当前目录下有的*.orig文件去掉.orig,有同名文件则覆盖。
rename_file.sh
#! /bin/bash
for f in $(find . -name '*.orig' -type f)
do
rename -f 's/.orig$//' $f
done
Linux rename命令:https://blog.csdn.net/mayue_web/article/details/106239424
Windows 批量重命名
@echo off & setlocal enabledelayedexpansion
pushd %~dp0
::指定起始文件夹
set DIR="C:\Users\mayue\Desktop\test_c"
echo DIR=%DIR%
for /R %DIR% %%f in (*.orig) do (
set m=%%f
set u=!m:.orig=!
move /y "%%f" "!u: =!"
)
pause
批处理重命名文件,去掉文件名中指定的字符:https://blog.csdn.net/weixin_33895657/article/details/93371312
@echo off&setlocal enabledelayedexpansion
pushd %~dp0
for /f "delims=" %%i in ('dir /s /b *.cs') do (
set m=%%i
set u=!m:CM_=!
move "%%i" "!u: =!"
)
第三行中的 *.cs 表示为要需要重命名的文件类型 为 当前目录下的所有cs文件
第五行中的 CM_ 表示要去掉的字符。
关于批量删除文件名中特定字符串前的内容批处理改进:
https://zhidao.baidu.com/question/362432818247770572.html
@echo off
setlocal enabledelayedexpansion
set /p str=请输入来要删除源哪个字百符串前的内度容知:
for %%i in ("*%str%*") do (
set "FileName=%%i"
set "FileName=!道FileName:*%str%=%str%!"
echo !FileName!
ren "%%i" "!FileName!"
)
pause
遇到重名文件会失败。
参考资料
https://blog.csdn.net/mi2006/article/details/84451881