Stumbling Toward 'Awesomeness'

A Technical Art Blog

Monday, April 12, 2010

Drop Files on a Python Script

So I have always been wondering how you can create almost like a ‘droplet’ to steal the photoshop lingo, from a python script. A while ago I came across some sites showing how to edit shellex in regedit to allow for files to be dropped on any python script and fed to it as args (Windows).

It’s really simple, you grab this reg file [py_drag_n_drop.reg] and install it.

Now when you drop files onto a python script, their filenames will be passed as args, here’s a simple script to test.

import sys
f = open('c:\\tmp.txt', 'w')
for arg in sys.argv:
    f.write(arg + '\n')

When you save this, and drop files onto its icon, it will create tmp.txt, which will look like this:

X:\photos\2010.04 - easter weekend\fuji\DSCF9048.MPO
X:\photos\2010.04 - easter weekend\fuji\DSCF9049.MPO
X:\photos\2010.04 - easter weekend\fuji\DSCF9050.MPO
X:\photos\2010.04 - easter weekend\fuji\DSCF9051.MPO
X:\photos\2010.04 - easter weekend\fuji\DSCF9052.MPO

The script itself is the first arg, then all the files. This way you can easily create scripts that accept drops to do things like convert files, upload files, etc..

posted by admin at 12:33 AM  

1 Comment »

  1. Fun — I am having difficulty installing py_drag_n_drop.reg on a mac–

    Comment by Thomas Murphy — 2017/04/03 @ 12:41 PM

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress