#!/usr/bin/env python3
from os import walk, getcwd, path, listdir, removedirs
from pathlib import PurePath
from string import Template
from shutil import move

TITLE='移动文件夹cases/*到../'
VERSION='_v1.0.0_'

# ignore all of directories, include root level
IGNORE_DIRS = ['.git','bin','Lib','lib','Scripts','include','src','images','answer','exam']

# ignore all subs of directories, exclude root level
IGNORE_SUBS = []

# ignore all files mathes
IGNORE_FILES = []

# match folder name
MATCH_FOLDER = ['demo']

rootDir = './src/packages'

result = []
for root, dir, files in walk(rootDir):
    dir.sort()
    files.sort()
    match = path.basename(root)
    if match in IGNORE_DIRS:
        dir[:] = [] # ignore sub
        continue;

    if match in IGNORE_SUBS:
        dir[:] = [] # ignore sub
        continue;
    if match in MATCH_FOLDER:
        parentPath = path.join(root,'cases')
        for filename in listdir(parentPath):
            move(path.join(parentPath, filename), root)
        if not listdir(parentPath):
            removedirs(parentPath)
            print('Remove' + parentPath + '.\n')
        continue;
        

# print result
print('succed!')




#!/usr/bin/env python3
from os import walk, getcwd, path, listdir, removedirs
from pathlib import PurePath
from string import Template
from shutil import move

TITLE='移动文件夹cases/*到../'
VERSION='_v1.0.0_'

# ignore all of directories, include root level
IGNORE_DIRS = ['.git','bin','Lib','lib','Scripts','include','src','images','answer','exam']

# ignore all subs of directories, exclude root level
IGNORE_SUBS = []

# ignore all files mathes
IGNORE_FILES = []

# match folder name
MATCH_FOLDER = ['demo']

rootDir = './src/packages'

result = []
for root, dir, files in walk(rootDir):
    dir.sort()
    files.sort()
    match = path.basename(root)
    if match in IGNORE_DIRS:
        dir[:] = [] # ignore sub
        continue;

    if match in IGNORE_SUBS:
        dir[:] = [] # ignore sub
        continue;
    if match in MATCH_FOLDER:
        parentPath = path.join(root,'cases')
        for filename in listdir(parentPath):
            move(path.join(parentPath, filename), root)
        if not listdir(parentPath):
            removedirs(parentPath)
            print('Remove' + parentPath + '.\n')
        continue;
        

# print result
print('succed!')




#!/usr/bin/env python3 # ignore all of directories, include root level # ignore all subs of directories, exclude root level # ignore all files mathes # match folder name # ignore sub # ignore sub # print result