Friday, October 31, 2008

This is so recursive, it hurts


# this is so recursive, it hurts
for topdir in args:
    for root, dirs, files in os.walk(topdir):
        for file in files:
            for regexp in patterns:
                if re.search(regexp, file):
                    file = os.path.join(root, file)
                    if verbose:
                        sys.stdout.write("file name: %s\t" % file)
                        p = os.stat(file)
                        a, m, t = (
                             time.strftime("%Y-%m-%dT%H:%M:%S",
                                        time.gmtime(p.st_atime)), 
                             time.strftime("%Y-%m-%dT%H:%M:%S", 
                                        time.gmtime(p.st_mtime)), 
                             time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()), )
                        sys.stdout.write( "atime: %s\tmtime: %s\tnow: %s\n" %
                             (a,m,t))
                    else:
                        print file
What a huge, ugly, monster, I'm glad the finished code doesn't look like that lol.

1 comment:

  1. I've elected to declassify this one, because it is just so darn funny lol --- was wondering where I saved the snippet of `the worst code I've ever written`

    ReplyDelete