Automatic delete files, but keep youngest 10 files

Forum about all other NON Home automation stuff can be placed here....
Post Reply
Verkenner
Member
Member
Posts: 338
Joined: Tue May 27, 2008 6:14 pm
Location: Netherlands

Automatic delete files, but keep youngest 10 files

Post 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
Best regards, Verkenner
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Automatic delete files, but keep youngest 10 files

Post 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
Bram
Alexander
Global Moderator
Global Moderator
Posts: 1532
Joined: Sat Mar 10, 2007 11:19 pm
Location: Netherlands

Re: Automatic delete files, but keep youngest 10 files

Post by Alexander »

Alexander
Edwin2008
Advanced Member
Advanced Member
Posts: 721
Joined: Fri Nov 28, 2008 4:14 pm
Location: Netherlands

Re: Automatic delete files, but keep youngest 10 files

Post by Edwin2008 »

Great, was looking for this for a long time :)
** edwin **
User avatar
Fantic
Member
Member
Posts: 201
Joined: Sat Feb 21, 2009 2:11 pm
Location: Loenen, UT, Netherlands
Contact:

Re: Automatic delete files, but keep youngest 10 files

Post 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
Regards, Maarten.
Never let a computer know you're in a hurry.
Post Reply

Return to “Off Topic”