Here is some code that I got from someone in IRC. I don't remember his name and I never tried it. But I think it's bad to lose the code. So I hosted it here.
The original source of this was ajwillia.ms, the code was made available at http://andywilliams.me/Files/.
Maybe I should create a git repo for this, but as it's very old a newer version that actually works is probably required first.