Last active
August 29, 2015 14:28
-
-
Save avin/1cd98892a3a0296f65cf to your computer and use it in GitHub Desktop.
Remove oldest files in folder by total files count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
set Folder=c:\test\oldfiles | |
set MaxFiles=3 | |
set FileExt=.png | |
:start | |
dir "%Folder%\*%FileExt%" /a-d | find /c "%FileExt%" > NUMfiles.### | |
set /p count=<NUMfiles.### | |
echo %count% | |
set OldestFile= | |
for /f "delims=" %%a in ('dir /b /o:d "%Folder%" 2^>NUL') do ( | |
set OldestFile=%%a | |
goto Break | |
) | |
:Break | |
if %count% LEQ %MaxFiles% ( | |
echo No old files! | |
) else ( | |
del "%Folder%\%OldestFile%" | |
goto start | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment