import os.path,sys,re,string

matcher = re.compile("(.*)-small\.jpg")

def foreachimage(arg, dirname, names):
    print dirname+"index.html"
    f = open(dirname+"index.html", "w")
    
    f.write("<html><head><title></title></head><body>\n<p>")
    
    try:
        names.remove(".thumbnails")
    finally:pass
    try:
        names.remove(".xvpics")
    finally:pass
    for n in names:
        fname = dirname+n
        if os.path.isfile(fname):
            picture = matcher.match(n)
            if picture:
                h = picture.group(1)
                print "\t", h
                f.write("<table border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"%s-medium.jpg\"><img src=\"%s-small.jpg\"/></a></td></tr><td><a href=\"%s\">%s</a></td></tr></table>\n" % (h, h, h+".JPG", h))
    f.write("</p></body></html>\n")
    f.close()

print sys.argv
os.path.walk(sys.argv[1], foreachimage, "")
