Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (37 sloc) 1.16 KB
"""Part of my photo revising suite of tools, including and
Handles POSTs from the local HTML page generated by for choosing which
pictures I want to keep.
There are two query parameters. dir is the fully qualified directory that
contains the pictures. keep is one or more picture filenames. This script makes
a no/ subdirectory and moves all the files there except the 'keep' ones.
__author__ = ['Ryan Barrett <>']
import cgi
import cgitb
import errno
import glob
import os
import shutil
import stat
form = cgi.FieldStorage()
dir = form.getfirst('dir')
no_subdir = os.path.join(dir, 'no')
except OSError, e:
if e.errno != errno.EEXIST:
os.chmod(no_subdir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
to_keep = form.getlist('keep')
all_files = glob.glob(os.path.join(dir, '*.*'))
for f in all_files:
if os.path.isfile(f):
shutil.move(f, no_subdir)
print 'Content-Type: text/html'
print 'Keeping %d out of %d files in %s.' % (len(to_keep), len(all_files), dir)
for f in to_keep:
print '<br />' + f
shutil.move(os.path.join(no_subdir, f), dir)