Ok, challence accepted :)
Here's what I came up with (with my admittedly non-substantial python skills). The two versions are very similar: the main difference is python's wordier syntax. The shell language, being more special, has some handy (though arguably somewhat obscure) syntactic shortcuts.
But as I said, I haven't coded much in python, so if I missed something essential and the python version can be compacted substantially, I'd like to know.
#!/usr/bin/pythonimport osimport sysimport shutilif len(sys.argv) == 2: # create newdir if it doesn't exist if not os.path.exists(sys.argv[1]): os.mkdir(sys.argv[1]) # for each file for root,dirs,files in os.walk("."): for name in files: fullname = os.path.join(root, name) # transform name, copy file if not os.path.isdir(fullname): shutil.copy(fullname, os.path.join(sys.argv[1], fullname.lstrip('./').replace('/', '_')))else: # print help if no arguments given print 'Usage: flatten.py newdir'