Because I have multiple back-up copies of all files, I use the following batch file to rename files so that I don't have to go into each drive/folder to rename files manually. The batch file works fine for renaming files. However, when renaming folders, sometimes it works, the other time, it generates another folder with the corrected name. When this happens, it doesn't happen to every folders to be renamed, only some of the folders.
Is there something wrong with the batch file? How can it be corrected?
chcp 65001
if exist C:\rename-all-4.txt del c:\rename-all-4.txt
SETLOCAL EnableDelayedExpansion
(for /f "tokens=1,2 delims=;" %%A in ('"TYPE C:\RENAME-ALL.txt"') do (
echo %%A | find /i "\"
if errorlevel 1 (
RENAME "D:\!mypath!%%A" "%%B"
RENAME "E:\!mypath!%%A" "%%B"
RENAME "\\PC1\D\!mypath!%%A" "%%B"
RENAME "\\PC1\E\!mypath!%%A" "%%B"
) ELSE (
echo "found pattern"
echo %%A
set mypath=%%A
echo mypath is !mypath!
)
)
) >> C:\RENAME-ALL-4.txt 2>&1
endlocal
CD /D C:\
The following is a shortened input file. After running the batch file, the original folder (中国人民银行_files) still exists along with a new folder (中國人民銀行_files).
News\
中国人民银行_files;中國人民銀行_files
rename
command. It will do it for you. On Debian systems you can install it withapt install rename
.folder\
, and the line afterwards containing file names:fileX;fileY
?