Python: flatten directories
I'll typically wrap the main body of my code in a python script in a function and break the code apart into more functions, allowing me to reuse that code later.

import os
import shutil
import sys

def flattenDirectory(location, action, actuallyMoveOrCopy=True):
   """ This function will move or copy all files from subdirectories in the directory location specified by location into the main directory location folder
       location - directory to flatten
       action - string containing m(ove) or M(ove) or c(opy) or C(opy)"""
   #Your code here

if __name__ == "__Main__":
    #same code to find currentDirectory here
    actuallyMoveOrCopy = len(sys.argv)&gt;1 and sys.argv[1] in ['m', 'M', 'c', 'C']
    flattenDirectory(currentDirectory, sys.argv[1], actuallyMoveOrCopy)


Now you can still run this code as you normally would, but should you need it in another script you can use it in an import without having to worry about the code automatically running at the time of import.