Hi
How do I delete all files in a directory that are older than 1 month?
Thanks
Hi
How do I delete all files in a directory that are older than 1 month?
Thanks
Hi Rob,
I guess you would want to do something like this:
Start with the documentation links to the keywords I used:
*** Settings ***
Library OperatingSystem
*** Test Cases ***
Old Files
${curr_y} ${curr_m} Get Time year,month
${files}= List Files In Directory c:/path/to/your/files
FOR ${file} IN @{files}
${y} ${m} = Get Modified Time ${file} year,month
IF '${curr_y}' != '${y}'
Remove File ${file}
ELSE IF '${curr_m}' != '${m}'
Remove File ${file}
END
END
This will remove any file that was not modified this month, which would be fine if you ran it on the last day of the month, but might not be what you want on the first of the month.
This should however give you the keywords you need to achieve what you want, just if you need to check whether to or not to remove files from the previous month you’ll need to get the day as well and do some extra checking.
Hope this helps,
Dave.
Thanks Dave