Page 1 of 1

Automatic delete files, but keep youngest 10 files

Posted: Sun Jun 24, 2012 1:52 pm
by Verkenner
Sorry, non Domo

Some application puts periodical a new photo in a Directory.
So that directory grows and grows.
The photo's have not the same name.

I want to keep maximum the youngest (newest) 10 pictures.
What tool can I use to automatic delete the older files?
Homeseer Pro and Windows7

Anyone used Powershell?

Thanks

Re: Automatic delete files, but keep youngest 10 files

Posted: Sun Jun 24, 2012 2:14 pm
by AshaiRey
Just make a vbscript to delete the files based on the date info and let it run in the schedular of Win7 or use a HS event.

Google on - vbscript delete files older then
Example : http://community.spiceworks.com/scripts ... ge-in-days

Re: Automatic delete files, but keep youngest 10 files

Posted: Sun Jun 24, 2012 10:38 pm
by Alexander

Re: Automatic delete files, but keep youngest 10 files

Posted: Mon Jun 25, 2012 8:30 am
by Edwin2008
Great, was looking for this for a long time :)

Re: Automatic delete files, but keep youngest 10 files

Posted: Mon Jun 25, 2012 6:54 pm
by Fantic
or use this standard windows (vista and up) tool http://technet.microsoft.com/en-us/libr ... 1(v=ws.10)
with this cmd:
rem -----------------------------------------------------------------
rem use the following set of 2 line as many times as you need first set the number of days you want the files to remain
rem keep in mind that you will need to seperate dir name and filename with a space
rem -----------------------------------------------------------------
set DaysToKeepLogs=2
call :RemoveFiles d:\pictures *.jpg

goto :EOF

rem ------------------------------------------------------------------------------
rem Remove the given files (%2) from the given directory (%1)
rem ------------------------------------------------------------------------------
:RemoveFiles
set Dir=%1
set Files=%2

if "%Files%"=="" set Files=*.*

rem *** List files to be removed in logfile ***
%Tools%\forfiles.exe -d-%DaysToKeepLogs% -p%Dir% -m%Files% -c"cmd /c echo %Dir%\@FILE" >>%Log%

rem *** Remove file from server ***
%Tools%\forfiles.exe -d-%DaysToKeepLogs% -p%Dir% -m%Files% -c"cmd /c del %Dir%\@FILE"

goto :EOF