I'm trying to create a .bat file that will copy all files that end with "XX" in three separate folders. I want it to put them all in one folder but add an incremental number to the end of the names (that way there aren't duplicate file names). After reading answers to my original question, I have written it again. But it still isn't copying everything because it gets duplicate filenames.
:: The setlocal line should put before the for loop:
setlocal EnableDelayedExpansion
set _a=0
for /D %%D in ("R:\SQL QUERIES\Mark\text append testing\*") do (
::Same as set /a _a=_a+1
SET /A _a+=1
echo !_a!
xcopy /Y /S "%%~D\*XX*" "R:\SQL QUERIES\Mark\conversion_scripts"
ren "R:\SQL QUERIES\Mark\conversion_scripts\*XX*" *!_a!
)
pause