これは少し注意が必要です。私の解決策は、バージョン番号が既存のフォルダー名の最後のスペースの後の残りのテキストであると想定しています。
以下のコードは、名前に少なくとも1つのスペースがある現在のディレクトリ内のすべてのフォルダの名前を適切に変更します。サブフォルダに戻ることはありません。!
バージョンテキストにまたはが含まれているとコードが壊れます=
が、問題になる可能性はほとんどありません。
@echo off
setlocal disableDelayedExpansion
for /d %%F in ("* *") do (
set "folder=%%F"
setlocal enableDelayedExpansion
for %%A in ("!folder: =\!") do (
for /f "eol=: tokens=* delims=v." %%B in ("%%~nxA") do (
if "%%~nxA" neq "v.%%~B" ren "!folder!" "!folder:%%~nxA=v.%%~B!"
)
)
endlocal
)
サブフォルダーに再帰する場合は、外側のループが必要です。フォルダーは逆の順序で並べ替えて、最も深いフォルダーが最初に処理されるようにする必要があります。
@echo off
setlocal disableDelayedExpansion
for /f "eol=: delims=" %%D in ('dir /s /ad /b * ^| sort /r') do (
pushd "%%D"
for /d %%F in ("* *") do (
set "folder=%%F"
setlocal enableDelayedExpansion
for %%A in ("!folder: =\!") do (
for /f "eol=: tokens=* delims=v." %%B in ("%%~nxA") do (
if "%%~nxA" neq "v.%%~B" ren "!folder!" "!folder: %%~nxA= v.%%~B!"
)
)
endlocal
)
popd
)