我试图通过在文件名中添加前缀来重命名目录中的文件。在这种情况下,我尝试添加的前缀是1-
。
@echo off
@setlocal enableextensions enabledelayedexpansion
cd %folder%
for %%a in (*.txt) do (
set var tem=%%a
rem checking file name contains 1- as prefix
if not x%tem:1-=%==x%tem% (
echo file is renamed all ready
)else(
ren "%%a" "1-%%a"
)
)
预期输出:不应重命名重命名的文件
答案 0 :(得分:0)
@echo off
setlocal enableextensions enabledelayedexpansion
cd %folder%
for %%a in (*.txt) do (
rem Set file name to "tem" variable
set "tem=%%a"
rem Checking if two first chars of file name are "1-"
if "!tem:~0,2!" == "1-" (
echo file is renamed allready
) else (
ren "%%a" "1-%%a"
)
)