重命名文件的批处理文件也尝试重命名目录

batch file to rename files also tries to rename directories

以下批处理文件用于从 txt 文件中获取目录和文件名,并根据给定的名称重命名目录中的文件。

SETLOCAL EnableDelayedExpansion

(for /f "tokens=1,2 delims=;" %%A in ('"TYPE C:\RENAME-ALL.txt"') do (
echo %%A | find /i "\" 
 if !errorlevel! equ 1 (
RENAME "D:\!mypath!%%A" "%%B" 
 ) ELSE (
echo "found pattern"
echo %%A
set  mypath=%%A
  echo mypath is !mypath!
 )
)
) >> C:\RENAME-ALL-4.txt 2>&1
endlocal

========== RENAME-ALL.TXT ================

mydirectory\photos19\  <= this is the directory
IMG_20190729_064619.jpg;IMG_20190825_064619.jpg   <=former name is replaced by the latter name

在这种情况下,批处理文件将 mydirectory\photos19 中的文件 IMG_20190729_064619.jpg 重命名为 IMG_20190825_064619.jpg。

但是,批处理文件还尝试将 mydirectory\photos19 重命名为“”(这不应该发生。)这可以被抑制吗?怎么样?

SETLOCAL EnableDelayedExpansion

(for /f "tokens=1,2 delims=;" %%A in ('"TYPE C:\RENAME-ALL.txt"') do if "%%B"=="" (
  echo "found pattern"
  echo %%A
  set  "mypath=%%A"
  echo mypath is !mypath!
 ) ELSE (
  RENAME "D:\!mypath!%%A" "%%B" 
 )
) >> C:\RENAME-ALL-4.txt 2>&1
endlocal