Python : copy directory in another directory
Question: I have a directory "D:/INPUT/test1" that I'd like to copy in another directory
"D:/OUTPUT".

I tried many methods but none of them have worked.

For example I tried the method explained at
_https://stackoverflow.com/questions/15034151/copy-directory-contents-into-a-
directory-with-python_ , that is to say :

    
    
    import distutils.core
    
    # copy subdirectory example
    fromDirectory = "D:/INPUT/test1"
    toDirectory = "D:/OUTPUT"
    
    distutils.dir_util.copy_tree(fromDirectory, toDirectory)
    

-> The directory "D:/OUTPUT" is well created but there is nothing inside.

Then I tried the shutil.copytree method but I get the same result.

Would you have any suggestions ? Thanks !


Answer: 
    import shutil, errno
    
    def copyanything(src, dst):
    try:
        shutil.copytree(src, dst)
    except OSError as exc: # python >2.5
        if exc.errno == errno.ENOTDIR:
            shutil.copy(src, dst)
        else: raise
    

