Automatically deleting old files from recycling bin while keeping the new ones?

25

9

I want an explorer add-on which will delete old files from recycling bin after a time period.

For example, I want to set the time limit to 30 days. When I delete a file in Windows, the software will keep a record of its delete-time. Every day, it will scan for deleted file whose age has reached to 30 days, and delete if there is any.

Is there any software like this?

hkBattousai

Posted 2012-06-09T12:25:07.637

Reputation: 2 711

It's not an explorer add on, and it's only 24 hours, but CCleaner has this option http://i.imgur.com/JaeJhzU.png

– Matthew Lock – 2014-11-18T04:16:03.390

Perhaps, instead of setting a time limit, you could have the Recycle Bin automatically delete the oldest items when a certain size limit has been reached? Would this be acceptable? – William Jackson – 2012-06-09T16:44:54.033

3@WilliamJackson That can be a solution for those who have limited hard disk space. But in my case, I want to make sure that I won't regret emptying recycling file because of loss of a recently deleted file. With this system, I will just forget about the recycle bin, it will empty itself automatically, and I will have plenty of time to recover a deleted file if I happen to regret it afterwards. – hkBattousai – 2012-06-09T17:02:17.437

1On gnu/linux world, KDE has this feature, and I think it's great for usability. Why should I keep in the trash can files for more than, say, 1 month? This approach doesn't clutter your trash can with old files that won't be relevant to you any more, so it's a lot easier to find and recover one or more files when you need it (really useful if you work a lot wit text files, that are always small), and don't waste disk space with files no more useful to you. – gerlos – 2013-07-05T09:11:40.357

Answers

9

RecycleBinEx is a simple application for Windows that does exactly what you ask. See: http://www.fcleaner.com/recyclebinex

On Mac OSX, Hazel does the same thing (among the others): http://www.noodlesoft.com/

KDE Plasma ships this feature as default, so if you're running Kubuntu, Arch, Chackra Linux or any other distro with KDE, you already have this feature. Just look at Dolphin configuration window.

On Ubuntu Unity, Gnome or any other gnu/linux desktop environment providing a standard FreeDesktop.org Trash feature you can use AutoTrash to do this thing: http://www.logfish.net/pr/autotrash/
Similar behaviour can be accomplished also with trash-cli, that could be used also to send files to trash can right from the command line. See: https://github.com/andreafrancia/trash-cli

Most email apps out there also have this feature for their "trash can".

On Android there isn't any "trash can" by default (when you delete it, it's gone forever), but you can install apps like Dumpster to (somehow) get similar features: http://www.dumpsterapp.mobi/

As said above, I think that automatically removing old files from trash can is a great feature to make it more usable, since it reduces clutter (are those files you trashed 3 months ago still relevant to you? And ALL those old revisions of the same file?) and makes easier to find what you want to recover (this is the reason for having a "trash can" on our computers, after all), still being safe.

It's even more useful if you work a lot with text files (code or prose), that most of the time are small and don't need a lot of space (so may never reach your trash can quota). This way you won't even need to periodically "empty your trash can". You just know that you have a window of time for recovering your "trashed" files if you need to.

Looking at most cloud services out there (Dropbox, Google Drive, Simplenote, ...), most of them seem to have a similar policy for deleted files. I really think it's the right thing to do with your files, and they seems to think so.

gerlos

Posted 2012-06-09T12:25:07.637

Reputation: 586

1I've been using this software since you posted your answer here. It is quite good. I'm satisfied with it. I recommend it. This was exactly what I was looking for. Thanks for your answer. – hkBattousai – 2014-10-08T08:55:27.293

1

A nice add to that list is trash-cli, a command line trash tool similar to autotrash, that lets you send files to trash even from the command line. See http://www.webupd8.org/2010/02/make-rm-move-files-to-trash-instead-of.html and https://github.com/andreafrancia/trash-cli

– gerlos – 2014-10-09T09:34:16.300

Will RecycleBinEx work in Windows 10? It seems to not be a default feature offered in Windows 10. – still_dreaming_1 – 2017-03-01T16:33:22.390

1@still_dreaming_1 last time I tried (several months ago), RecycleBinEx seemed to work on Windows 10. But I don't use it as my main system, so I can't tell if it still work with recent updates of the system. – gerlos – 2017-03-01T18:18:57.470

1I just tried RecycleBinEx on Windows 10. The GUI has some strange behavior — some files in the recycle bin show up with single-character filenames — but the command-line option to remove files older than X days seems to work fine. To see the command line options, type "RecycleBinEx.exe /?" at the command line. – Aaron – 2017-05-11T14:29:29.083

17

I don't know of any Explorer add-ons, but like most things in Windows, this can be done with PowerShell:

ForEach ($Drive in Get-PSDrive -PSProvider FileSystem) {
    $Path = $Drive.Name + ':\$Recycle.Bin'
    Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue |
    Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } |
    Remove-Item -Recurse
}

Save this script as a text file with a .ps1 extension. You can then use Task Scheduler to run this at regular intervals.

First, though, you need to permit the execution of PowerShell scripts, because by default you can only execute commands typed directly into the PowerShell prompt. To do this, open PowerShell and type in the following command:

Set-ExecutionPolicy RemoteSigned

Type in "y" or "yes" when prompted. See Get-Help Set-ExecutionPolicy for more information.

Now open Task Scheduler and create a new task with the following parameters:

  1. Under the "General" tab, enter a name and check the "Run with highest privileges" option
  2. Under the "Triggers" tab, add a new trigger and set the task to run daily
  3. Under the "Actions" tab, add a new action:
    • leave the type as "Start a program"
    • set the "Program/script" field to C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • set the "Add arguments" field to -NonInteractive -File "C:\path\to\script.ps1"
  4. Under the "Conditions" tab, uncheck "Start the task only if the computer is on AC power"

Line-by-line explanation of the script:

ForEach ($Drive in Get-PSDrive -PSProvider FileSystem) {

This gets a list of all drives in the computer and loops through them one by one. The -PSProvider FileSystem parameter is required to only return disk drives, because PowerShell also has pseudodrives for various other things like registry hives.

For more information, see Get-Help Get-PSDrive and this tutorial on loop processing in PowerShell.

$Path = $Drive.Name + ':\$Recycle.Bin'

This constructs the path to the Recycle Bin folder on the current drive. Note the use of single quotes around the second part, to prevent PowerShell from interpreting $Recycle as a variable.

Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue |

This returns all files and subfolders under the given path (the one we constructed with the previous command). The -Force parameter is needed to go into hidden and system folders, and the -Recurse parameter makes the command recursive, ie. loop through all subdirectories as well. -ErrorAction is a standard parameter for most PowerShell commands, and the value SilentlyContinue makes the command ignore errors. The purpose of this is to prevent errors for drives that have been configured to delete files immediately. The | symbol at the very end pipes the results to the next command; I split it up to several lines for better readability.

For more information, see Get-Help Get-ChildItem.

Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } |

This simply filters the results from the previous command and returns only those that are older than 30 days. $_ refers to the object currently being processed, and the LastWriteTime property in this case refers to the date and time that the file was deleted. Get-Date returns the current date.

For more information, see Get-Help Where-Object and Get-Help Get-Date.

Remove-Item -Recurse

This simply deletes the items passed to it by the previous command. The -Recurse parameter automatically deletes the contents of non-empty subfolders; without it, you'd be prompted for such folders.

For more information, see Get-Help Remove-Item.

Indrek

Posted 2012-06-09T12:25:07.637

Reputation: 21 756

3Alternatively to globally setting the execution policy, you can create a command line that sets it for the process: powershell -ExecutionPolicy RemoteSigned -File .\myscript.ps1. – jpmc26 – 2014-09-24T15:43:19.343

Recycle Bin in explorer details view has a special column: "Date Deleted", I wonder how can we filter using that instead? LastWriteTime is not a same thing by any means. – Ciantic – 2015-10-21T04:36:40.207

Spoke too soon, found this: http://baldwin-ps.blogspot.fi/2013/07/empty-recycle-bin-with-retention-time.html it has a "Date Deleted" also in it.

– Ciantic – 2015-10-21T04:45:03.403

I set it up. Thank you very much for explaining it in this much detail. – hkBattousai – 2012-06-09T16:58:01.420

4

The Windows Recycle Bin automatically deletes older files when it reaches it's maximum size: What happens when Recycle Bin uses up its allocated space?

You can control this from the properties of the Recylce Bin

enter image description here

Matthew Lock

Posted 2012-06-09T12:25:07.637

Reputation: 4 254

1This answer does not answer the question, as this mechanism does not take into account the specific age of the files; it only deletes the oldest files of arbitrary age to maintain a preset volume of data. – Jonathan J – 2015-05-29T16:42:37.123