WORKINGDIR "c:\folder\to\clean" SET temp = %datetime DATETIMESUB temp 30 /day SET thirty_days_ago = temp :loop GETNEXTFILE "*" /oldest IFERROR RETURN $ERROR_SUCCESS IFDATETIME> %nextfiledatetime thirty_days_ago RETURN $ERROR_SUCCESS ;; File is more than 30 days old, so delete it DELETE %nextfile ;; It's a good idea to make sure the delete doesn't fail due ;; to a permissions issue (want to avoid getting stuck in ;; an infinite loop). IFERROR RETURN GOTO loop