Scripts
Here you can find some scripts I made. The python ones require Python (obviously), which you can get from ActiveState.
SortSize 1.0
Sortsize is a small Python script that calculates which files from a given directory fit best into the specified size. Say, for example, that you want to burn a DVD with files from a directory, but you don’t know which ones to include so that the DVD has as less wasted space as possible. You run sortsize, it tries out all file combinations and tells you which one leaves the least wasted space. The simplest way to use it is to open a command prompt, cd to the directory with your files and run it with the size as an argument. By the way, having Psyco installed can speed this script up by ten times or so. Valid size units are:
- k – kilobyte
- m – megabyte
- g – gigabyte
- c – CD size (736294912 bytes)
- d – DVD size (4700000000 bytes)
For example, a typical command line would be sortsize.py 1d, which would calculate the size of one DVD. You can also use 2d, 3c, 10m, etc.
Command-line options (you can see these by running sortsize.py --help):
-m SIZE, --minimum=SIZE |
If you have lots of small files in that directory and only want to include files of size SIZE or larger, use this option. |
-g SIZE, --margin=SIZE |
If you don’t care about filling the entire space and would be fine with leaving a bit of slack, specify this option and searching will stop if it finds a combination that leaves at least SIZE bytes free (you can use k, m, g, etc here as well). |
-c, --compatible |
Just prints a list of names, so you can copy-paste it into a batch file. |
-v, --verbose |
Talks a lot. |
-l, --logged |
Logs stuff. Not very useful, but doesn’t slow down the script. |
-f, --fuse=N |
By default, SortSize considers files that begin with the same 4 letters as one big file. This is useful if, for example, you want to burn a movie and its subtitles, which can’t really be separated. If you find that it thinks of multiple files as one decrease this (0 disables it) or if you want SortSize to look at more characters before it considers two files equal increase it. |
-s, --size |
Sort the file list by size instead of name. |
Distributed under the GNU GPL.
PCREname 1.0
PCREname renames files in a directory using regular expressions. For example, if you have files test1.txt to test100.txt and run pcren test sample it will rename files to sample1.txt, sample2.txt, etc. You can use parentheses to capture text and tokens in the format “\1” to replace them. For example, in the above files, pcren test(\d+).txt "Test file \\1.doc" will rename the files to Test file 1.doc, Test file 2.doc, etc.
Command-line options (you can see these by running pcren.py --help):
-p, --preview |
Only preview changes (do not actually rename). |
Distributed under the GNU GPL.
Episode renamer 0.1
This script renames all video files (of TV show episodes) in a given directory according to their proper names from IMDB. If you have AtomicParsley and the videos are in MP4 format, the script can automatically add the proper tags so iTunes recognizes the videos correctly.
Usage:
Command-line options (you can see these by running episode_rename.py --help):
-p, --preview |
don’t actually rename anything |
-a, --use-atomic-parsley |
use AtomicParsley to fill in the files’ tags |
Distributed under the GNU GPL.
POPdel 1.0
POPdel deletes emails from your email server. If you’ve ever gone on vacation and returned to find a few thousand spam emails on your account and don’t want to bother downloading them, this script will do the job just fine. Point it to your mail server and let it delete everything in a few minutes.
Note: In case you didn’t understand, this DELETES ALL EMAILS FROM YOUR POP SERVER. So don’t say I didn’t warn you.
Usage:
popdel.py <server> <username> <password>
Distributed under the GNU GPL.
I think, in PCREname, you got the second example wrong. The command should be: pcren test(\d+).txt "Test file \1.doc".
Submitted by Aggelos Orfanakos (not verified) on Sun, 29/01/2006 - 01:10.Oops, for some reason that was escaped and didn't appear. Efxaristo :)
Submitted by Stavros on Sun, 29/01/2006 - 02:03.---
Vidi, Vici, Veni.
Thanks for the POPdel script, it's worth mentioning that if you need to get an email that was sent to a spam filled address that you haven't used in years (like I did), you can change
for intMessage in range(1, tplMessages[0] +1):
to say
for intMessage in range(1, tplMessages[0] -10):
to get keep just the last couple messages, it worked for me.
Submitted by Dave (not verified) on Wed, 29/11/2006 - 22:11.Indeed you can. In fact, you can tweak it however you want to keep the first or last ones, by using range(10, tplMessages[0] - 10 + 1) or something equivalent. Thanks for the tip!
Submitted by Stavros on Wed, 29/11/2006 - 23:14.---
Vidi, Vici, Veni.
Hello,
My mail server is at an local institution. Can I run your script under windows from my home in order to delete about 5000 messages? How?
Thank you,
YORG
Submitted by YORG (not verified) on Fri, 01/12/2006 - 08:21.Sure, just download python and run it, it's standard procedure.
Submitted by Stavros on Sun, 03/12/2006 - 19:38.---
Vidi, Vici, Veni.
It's AWESOME TOOL!!!
As a system administrator I'm eventually get this problem, I was writing bash scripts and etc, but they very slow... this way faster and more simple! and it does the job right!. totally recommend to everyone.
Submitted by MTS (not verified) on Fri, 12/01/2007 - 22:49.This helped me out a lot when I had 9000+ messages to delete.
Great work !
Submitted by Robert (not verified) on Sat, 10/02/2007 - 12:53.Glad I could be of use :)
Submitted by Stavros on Sat, 10/02/2007 - 15:37.---
Vidi, Vici, Veni.
I was going through over 50,000 old emails with a webmail interface, clicking select all, delete selected, one page at a time and thought there has to be a better way. And I found your script! I just changed the for loop to -500 so it would leave the most recent emails on the server. This will save me a ton of time.
Submitted by Wayne (not verified) on Tue, 13/10/2009 - 16:06.I'm glad you found it useful, thanks for the feedback!
Submitted by Stavros on Tue, 13/10/2009 - 16:18.Great stuff Poromenos, just what I was looking for.
Many thanks for this, I really appreciate you making your script available for publc use; I just saved myself a large amount of time with about 500-odd e-mails backed up in an old webmail folder and I am very grateful to you for your contribution!
Excellent work, keep it up. In my humble opinion, you are definitely doing your Karma a world of good!
Submitted by Cameron Barclay (not verified) on Sun, 15/04/2007 - 21:37.Thank you for your kind words, and if you have any suggestions for anything else that might be of use, I'm always listening :)
Submitted by Stavros on Mon, 16/04/2007 - 17:24.---
Vidi, Vici, Veni.
Hi, Nice website! Especially the python tutorial, although it took me more than 10 minutes. I don't mean the design, since that is just a Drupal theme. But the content!
Only I couldn't download the scripts. The link http://files/sortsize10.zip did not work for obvious reasons. Can you please correct this to the correct link and send me an email (if your reply doesn't do that automatically).
Cheers,
Submitted by Tim (not verified) on Tue, 05/06/2007 - 10:30.Tim
Bah, damn textile. The links should work now.
Submitted by Stavros on Tue, 05/06/2007 - 10:42.---
Vidi, Vici, Veni.
Nice Python Script!
nice POPdel Script! I had 56k worth of messages due to logging that I have to clear!
btw, just one problem, the password portion doesn't accept special characters. You may want to refine this part as most people nowadays uses complex password that includes special characters.
Submitted by Dragon (not verified) on Tue, 14/10/2008 - 03:41.Hello and thank you for your kind words. That seems to be a limitation of the console, you can enclose the password in quotes or just open the script and change
to
It worked perfect! thanx
Submitted by Anonymous (not verified) on Fri, 31/10/2008 - 09:19.I downloaded python but can't figure out how to run this. I have an address with over 40,000 emails in it that I need to purge. This is the most hope I've had yet.
Submitted by Anonymous (not verified) on Wed, 15/07/2009 - 16:31.Just run it from the command line or make a shortcut and enter your server address, your username and your password after the script's name.
Submitted by Stavros on Wed, 15/07/2009 - 16:32.I've tried to run popdel.py with phyton 2.6.4 using line like this:
popdel.py box.tin.it myemail@tin.it password
but i receive a Syntax error:
>>> popdel.py box.tin.it myemail@tin.it password
SyntaxError: invalid syntax
>>>
which is the right syntax ?
is there any examples ?
Thanks
Submitted by Mauro (not verified) on Wed, 18/11/2009 - 14:46.Yes, you don't have to launch python, just run the script from the command line.
Submitted by Stavros on Wed, 18/11/2009 - 14:54.