I have a batch file
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "my_date=%YYYY%%MM%%DD%" & set "time=%HH%%Min%"
set "minFiles=10"
setlocal EnableDelayedExpansion
rar a -t -rr D:\Backup\Arch\Backup_%_my_date%.rar D:\Backup\Backup.bak
for /f %%A in ('dir "D:\Backup\Arch\*.rar" /a-d-s-h /b ^| find /v /c ""') do if %%A leq %minFiles% goto :eof
:loop
for /f "delims=" %%a in ('dir /b /a-d /t:w /o:d "D:\Backup\Arch\*.rar"') do (
del "%%a"
goto :breakLoop
)
:breakLoop
pause
for /f %%A in ('dir "D:\Backup\Arch\*.rar" /a-d-s-h /b ^| find /v /c ""') do if %%A gtr %minFiles% goto :loop
It is supposed to rar a file and then check if there is more than 10 files in folder delete oldest file. It works well until in folder D:\Backup\Arch\ are 10 rar files.
But if in folder are 10 rar files and I start *.bat I get a new rar file in D:\Backup\Arch\ and now they are 11. It's supposed to go to next line delete one file if there are 11, but it doesn't delete. Why ?
rar is taking 2 or 3 hours.
When program is here
rar a -t -rr D:\Backup\Arch\Backup_%_my_date%.rar D:\Backup\Backup.bak
and it's archiving file when does it go to next line
for /f %%A in ('dir "D:\Backup\Arch\*.rar" /a-d-s-h /b ^| find /v /c ""') do if %%A leq %minFiles% goto :eof
It goes when rar is finished or right after command rar is send ?
How I can make program to go to the next line right after rar is finished ?
If I start a different bat with this part of code it works perfect and delete files
for /f %%A in ('dir "D:\Backup\Arch\*.rar" /a-d-s-h /b ^| find /v /c ""') do if %%A leq %minFiles% goto :eof
:loop
for /f "delims=" %%a in ('dir /b /a-d /t:w /o:d "D:\Backup\Arch\*.rar"') do (
del "%%a"
goto :breakLoop
)
:breakLoop
pause
for /f %%A in ('dir "D:\Backup\Arch\*.rar" /a-d-s-h /b ^| find /v /c ""') do if %%A gtr %minFiles% goto :loop
No comments:
Post a Comment