Delete Files In a Folder That Were Created Five Days Ago

Hi,

I have a folder that adds files every day automatically.

I want to create a macro that deletes the files created five days ago by everyday check.

How can I achieve that?

Thanks

Do the files have known names? Are the file names dated? Are the files in a folder with no other files?

There are a number of ways to go about it, but it depends on the folder’s other contents and the names of the files as to which is the easiest way.

The names don't contain the date info.

The names are random.

A folder only contains the MKV format files.

Well, you can use the For Each action and the Folder Contents collection to iterate through all the files in the folder.

And you can use the Get File Attribute action to get the creation date. And then you can compare that to NOW() and if it is > 5 days ago, then you can delete it with the Trash a File action.

So:

  • For Each variable "Path" in the Folder "Whatever"
    • Get File Attribute Creation Date of %Variable%Path% to variable "CDate"
    • If calculation NOW() - CDate > 5243600
      • Trash file %Variable%Path%

:warning: WARNING: You could easily delete the wrong files, or do a lot of damage with this. So before you start ensure you have a good full disk backup, and then use a Log action instead of a trash file to ensure only the correct files are going to be deleted before using the trash file action.

1 Like

Are these files that are being created in that folder? Downloaded to it? Moved to it from elsewhere? Depending on what you are doing you might need to use @peternlewis's suggestion above but based on the "added date" file attribute instead.

2 Likes