Dieser Code funktioniert mit folgenden Einschränkungen:
- keinen relativen Pfad für Source angeben (".." funktioniert nicht)
- Dateien mit Escape im Namen werden von XCOPY nicht als Ausnahme erkannt ("^") und immer kopiert
- Dateien mit einer Grössenangabe > 32bit/2 (2.147.483.647 Bytes = 2,14 GiB) werden immer als Ausnahme eingetragen (nie kopiert), der Windows-Batchprozessor kann nicht damit rechnen
- die Eingabe wird nicht auf Fehler überprüft (min > max usw)
Aufruf: min max (zB <s*****.cmd> 5000 6000)
Code:
@echo off &setlocal EnableDelayedExpansion
set "source=c:\*.jpg"
set "destination=g:\bilderordner"
set "exclusionfile=%random%%random%"
set "exclusionfile=%temp%\%exclusionfile:~-8%.txt"
goto :main
:setexclusion
set "tpath=%~pnx1"
echo !tpath!>>!exclusionfile!
goto :eof
:main
if "%1"=="" (goto :eof) else (set /a "min=%1") || goto :eof
if "%2"=="" (goto :eof) else (set /a "max=%2") || goto :eof
for /f "delims=" %%i in ('dir !source! /s /a-d /b') do (
set "tfile=%%i"
set /a "tsize=%%~zi" >nul 2>&1
if errorlevel 1 call :setexclusion "!tfile!"
if !tsize! LSS %min% call :setexclusion "!tfile!"
if !tsize! GTR %max% call :setexclusion "!tfile!"
)
xcopy !source! !destination! /s /exclude:!exclusionfile!
endlocal