liuyenting
4/5/2016 - 8:14 AM

Simple script to move all the files from subdirectory to root.

Simple script to move all the files from subdirectory to root.

#!/usr/bin/env python

import shutil, os, sys

# current working directory
dest_dir = os.getcwd()

dir = []
for root, dirs, files in os.walk(dest_dir):
    for name in files:
        if name != sys.argv[0]:
            print(name)
            old_path = os.path.join(root, name)
            new_path = os.path.join(dest_dir, name)
            shutil.move(old_path, new_path)
    dir.append(root)

for name in dir[1:]:
    shutil.rmtree(name, ignore_errors=True)