Rule to delete files

Hi,

I save my webcam pictures under /etc/openhab2/html:

		var SimpleDateFormat df = new SimpleDateFormat( "YYYYMMdd_HH:mm:ss" )
		var String Timestamp = df.format( new Date() )
		executeCommandLine("wget http://user:pass@ip/cgi-bin/viewer/video.jpg -O /etc/openhab2/html/BWL_" + Timestamp + ".jpg",2000)

Now I want to have a daily rule, which should delete old pictures:

 rule "taegliche"
    when Time is midnight
    then
	
	//get all files from "/etc/openhab2/html/"
        executeCommandLine("ls /etc/openhab2/html/ to ...???

       //loop over files; check if date older then 3 weeks, if yes, delete file   
        
       

    end

is it possible? Can someone help?

In the long turn I want to save my pictures in google photes. Maybe someone do it already and can give me a hint… maybe with IFTTT??

kind regards

I have solved this with a bash script that I periodically call via cron-job:

bash-script:

# remove files older than 5 days
find /media/fritzbox* -mtime +5 -exec rm {} \;
1 Like

The cron job @michel53 suggests is the more appropriate solution. But if you want to do it in openHAB,you want to use the find command. Run man find or search google for examples of find to figure out how to do it. The main difference will be the path and the -mtime argument.