Introduction:
Tumblr is a fun place, filled with pure insanity, madness and obsessing over minute changes in characters' facial expressions in a scene. Animated GIFs are a staple part of the Tumblr experience, and if you've ever tried your hand at their creation, you'll know the pain of getting the file to meet the size limitation.
If you're anything like me, you have, on more than one occassion, ended up with a folder filled with a mixture of GIFs under and over that 1 MB threshold. Wouldn't it be nice to have an easy way to purge the useless ones, without resorting to mandrolic acts?
Now you can with this handy batch script I created!
Well, you can if you are using windows.
Files:
Batch Script: cleanup.bat
Text File: cleanup.txt
Usage: cleanup.bat <relative folder path>
How to use:
There are two ways to use this.
- Put cleanup.bat into the folder you want to clean up and double click to run.
- Run it from command prompt, which allows you to specify a folder to delete from.
Both methods will create a log file in the working directory called "log.txt". You can change this by modifying the log variable in the batch file.
How it works:
The script is actually really simple and could be done in a single line using forfiles. I just wanted to add logging to it because it is nice to know what's going on. Unfortunately making nice logging means many extra lines and various error checks. But whatever, it is good scripting practice. I might mod it to make it show the total amount of files deleted at the end, but for now it just reports whether or not files were deleted and which ones.
Anyway, without logging, the code is simply:
forfiles /P . /M *.gif /C "cmd /c if @fsize gtr 1048576 (del @path)"forfiles is a pretty darn powerful tool that scans through all files in a certain path, finds the ones that meet the search criteria (masks, date created etc), then performs a command of your choice on it. It even gives you nice variables to play with, like @fsize, which is the file size, and the @path, which is the path of the file. It's an awesome command, and I suggest you play around with it.
Conclusion:
I might tweak this code a little bit, including a bit more error checking and better logging. The important thing is that it works. Well, at least it works on my computer.





