Wednesday, June 20, 2012

recursive renaming file names + folder names with a batch file


A batch file (winxp cmd) that recursively goes through a chose folder and sub folders and renames there files+folders with the following rules:
from all file + folder names, all uppercase+lowercase "V" and "W" letters need to be replaced with letters "Y" and "Z".
e.g. 11V0W must become 11Y0Z.

Answer

The following batch does this for the file names at least. Directories are a bit trickier (at least I couldn't come up with a non-infinite solution so far):
@echo off
setlocal enableextensions
for /r %%f in (*) do call :process "%%f"
endlocal
goto :eof

:process
pushd "%~dp1"
set fn=%~nx1
set fn=%fn:V=Y%
set fn=%fn:W=Z%
ren "%~nx1" "%fn%"
popd
goto :eof
But in theory it shouldn't be too hard to tack dir renaming onto this.

source:
http://stackoverflow.com/questions/717171/recursive-renaming-file-names-folder-names-with-a-batch-file

No comments: