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=SIZEIf 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=SIZEIf 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, --compatibleJust prints a list of names, so you can copy-paste it into a batch file.
-v, --verboseTalks a lot.
-l, --loggedLogs stuff. Not very useful, but doesn't slow down the script.
-f, --fuse=NBy 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, --sizeSort 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, --previewOnly 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, --previewdon't actually rename anything
-a, --use-atomic-parsleyuse 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.

Minor correction

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.
Re: Correction

Oops, for some reason that was escaped and didn't appear. Efxaristo :)
---
Vidi, Vici, Veni.

Submitted by Poromenos on Sun, 29/01/2006 - 02:03.
POPdel feature

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.
Re: POPdel feature

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!
---
Vidi, Vici, Veni.

Submitted by Poromenos on Wed, 29/11/2006 - 23:14.
POPdel

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.
Re: POPdel

Sure, just download python and run it, it's standard procedure.
---
Vidi, Vici, Veni.

Submitted by Poromenos on Sun, 03/12/2006 - 19:38.
It's AWESOME TOOL!!! As a

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.
Thanks !

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.
Re: Thanks

Glad I could be of use :)
---
Vidi, Vici, Veni.

Submitted by Poromenos on Sat, 10/02/2007 - 15:37.
POPdel

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.
Re: POPdel

Thank you for your kind words, and if you have any suggestions for anything else that might be of use, I'm always listening :)
---
Vidi, Vici, Veni.

Submitted by Poromenos on Mon, 16/04/2007 - 17:24.
Sortsize (and also the other scripts)

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,
Tim

Submitted by Tim (not verified) on Tue, 05/06/2007 - 10:30.
Re: Sortsize

Bah, damn textile. The links should work now.
---
Vidi, Vici, Veni.

Submitted by Poromenos on Tue, 05/06/2007 - 10:42.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Google ads

(You can disable these if you log in)