batch script to skip file is file name contains a specific prefix
Posted: 04 Feb 2020 03:01
hi,
I have below script that add a prefix to all files available in a folder.
how to include another if statement that if a file name already contains A23_ as prefix in the folder it should skip it?? pls help. thxs
@echo off
set "dir=C:\TEST"
set "pfx=A23_"
setlocal enabledelayedexpansion
for /r "%dir%" %%A in (*.txt) do (
set "txt=%%~nA"
if not "!txt:~0,13!"=="%pfx%" ren "%%A" "%pfx%%%~nxA"
)
pause
I have below script that add a prefix to all files available in a folder.
how to include another if statement that if a file name already contains A23_ as prefix in the folder it should skip it?? pls help. thxs
@echo off
set "dir=C:\TEST"
set "pfx=A23_"
setlocal enabledelayedexpansion
for /r "%dir%" %%A in (*.txt) do (
set "txt=%%~nA"
if not "!txt:~0,13!"=="%pfx%" ren "%%A" "%pfx%%%~nxA"
)
pause