I want to copy all files in all subfolders and prefix them with a user defined input using a batch script. The code below works, but ends up copying the copied files, thus resulting in a large list of files like
Test - Lastname.txt
Test - Test - Lastname.txt
Test - Test - Test - Lastname.txt
etc.
How do I stop it from repeating the procedure on already copied files?
@Echo OFF
setlocal enabledelayedexpansion
set /p input=Enter File Prefix:
for /r %%a in (*.txt) do for %%b in ("%%~dpa\.") do copy "%%~a". "%cd%\%%~nxb\%input% %%~nxa"
i think an if
Findstr
%input%
already exists in the filename, then skip to next file should work, similar to Batch Script Renaming File Prefix but no luck so far....