Page 1 of 1

batch script to skip file is file name contains a specific prefix

Posted: 04 Feb 2020 03:01
by nets
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

Re: batch script to skip file is file name contains a specific prefix

Posted: 05 Feb 2020 10:06
by Squashman
Your code is comparing 13 characters of the file name to 4 characters of your prefix string. That will never be true.