Isso deve fazer o trabalho:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
REM **************************************************
REM Source directory
SET source=C:\adjust\path\to\folder
REM Set folder name
SET folder_name=folder
REM **************************************************
REM Creating a new directory to sort out files
IF NOT EXIST "%source% TEMP" MD "%source% TEMP"
REM Sorting out files without duplicates
FOR /F "tokens=1,* delims=~" %%A IN ('DIR /S/B/A-D "%source%"') DO (
IF NOT EXIST "%%~fA~2%%~xB" COPY "%%~fA~1%%~xB" "%source% TEMP\%%~nxA~1%%~xB" >nul 2>&1
)
REM Sorting out files with biggest size
FOR /F "tokens=1,* delims=~" %%F IN ('DIR /S/B/A-D "%source%"') DO (
SET path=%%~dpF
SET name_1=%%~nF~
FOR /F "delims=" %%A IN ('DIR "%%~fF*" /S/B/O:-S') DO (SET biggest=%%A && CALL :copy)
)
REM Deleting all duplicates
RD /S /Q "%source%"
REM Renaming TEMP to source
REN "%source% TEMP" "%folder_name%"
CLS
ECHO.
ECHO Done^^!
ECHO.
PAUSE
:copy
SET name_2=%biggest:*~=%
COPY "%biggest%" "%source% TEMP\%name_1%%name_2%" >nul 2>&1 && DEL "%path%%name_1%*" >nul 2>&1
EXIT /B
Lembre-se: isso excluirá a pasta inteira e renomeará a pasta temporária de acordo. Se você tem algum arquivo que não tenha um ~
em seu nome, então esses arquivos serão deletados !!!