4coder/non-source/test_data/lots_of_files/backup.bat

30 lines
523 B
Batchfile
Raw Permalink Normal View History

2018-03-16 18:19:11 +00:00
@echo off
if not exist backup (mkdir backup)
set DT=%DATE%_%TIME%
set DT=%DT:/=.%
set DT=%DT::=.%
set DEST=backup\%DT%
mkdir %DEST%
copy %1\* %DEST%\*
REM Thanks to stackoverflow.com ~ dbenham for
REM this batch script.
set MAXBACKUPS=%2
set "delMsg="
for /f "skip=%MAXBACKUPS% delims=" %%a in (
'dir "backup\*" /t:c /a:d /o:-d /b'
) do (
if not defined delMsg (
set delMsg=1
echo More than %MAXBACKUPS% found - only the %MAXBACKUPS% most recent folders will be preserved.
)
rd /s /q "backup\%%a"
)