Code Monkey home page Code Monkey logo

file-declutter's Introduction

file-declutter

Script to Auto-Delete Files in a directory after a certain amount of time

What it does

The script is intended to reduce digital file clutter by auto-deleting files past a certain age.

It recursively scans a directory on your computer and records any files that it finds along with a timestamp for when they first appeared in the directory. If a file in that directory has been modified recently, it updates the "first appeared" timestamp to the file's modification time. If a file is more than 60 days old, then the script will delete it. The script will immediately delete any empty directories.

Why I made it

I liked the convenience of using the Linux /tmp directory to auto-delete files, but I wanted something with more persistence.

Example use cases

  • Experiment on copies of your files with new software so you don't screw up the original files
  • Saving memes to share with friends that will be stale in a few weeks
  • Edit photos, videos or audio files in different ways while you decide which version you will keep
  • For any short-term projects where you don't need to store your work long-term

How to use

  1. Create a directory at $HOME/Downloads/'2 months to live/'
  2. Create a directory logs/ inside that directory
  3. Set up a cron job or task scheduler to run the script every 6 hours or so.
  4. You can manually delete any files in the temp directory at any time, except for the cleanup_shelf file in the logs/ folder. Don't mess with that one, or it will reset the clock on all the other files.

How to customize for your setup

  • You can change the location of your "temp directory" in line 9.
  • You can increase or decrease the retention time in line 10.

Other notes

  • Not tested on Windows or Mac
  • The "hitdict" variable name is a play on words. We are creating a hit list of files to delete...but they are stored in a Python dictionary, so it's a hit dict instead. Clever?
  • I don't understand the different software licenses. As far as I'm concerned, this script is public domain.

file-declutter's People

Contributors

stampede avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.