@echo off
setlocal EnableDelayedExpansion
set destination=C:\put the destination folder here
set newName=10000
rem Read the text file line by line
for /F "delims=" %%a in (thefile.txt) do (
rem Check if a folder with that name already exists in the destination directory.
set "folder=%%~Na"
if exist "%destination%\!folder!" (
rem If yes, then rename the folder and copy it.
call :getNewName folder
)
rem If not, copy without renaming the folder.
md "%destination%\!folder!"
copy "%%~a" "%destination%\!folder!"
)
rem Finally, I want to sequentially rename all the folders in the destination starting with 0000.
cd /D "%destination%"
set n=9999
for /D %%a in (*) do (
set /A n+=1
if "%%a" neq "!n:~-4!" (
ren "%%a" "!n:~-4!"
)
)
goto :EOF
:getNewName folder
set /A newName-=1
set folder=%newName%
if exist "%destination%\%folder%" goto getNewName
exit /B