59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
import os
|
|
import random
|
|
from multiprocessing import Pool
|
|
import sys
|
|
sys.path.append('/home/thebears/Seafile/Designs/ML')
|
|
|
|
#rtpath = '/srv/ftp/hummingbird/2021'
|
|
rtpath = os.path.abspath(sys.argv[1])
|
|
#rtpath = os.path.abspath('/srv/ftp/hummingbird/2021/07/')
|
|
|
|
didir = list()
|
|
for di,dnames, fns in os.walk(rtpath):
|
|
numbers = di.split('/')[-3:]
|
|
if all([n.isnumeric() for n in numbers]):
|
|
didir.append(di)
|
|
|
|
|
|
|
|
|
|
def list_files(path):
|
|
for file in os.listdir(path):
|
|
if os.path.isfile(os.path.join(path, file)):
|
|
yield file
|
|
|
|
import shutil
|
|
import os
|
|
for cdr in didir:
|
|
|
|
files_origin = list()
|
|
for di, dnames, fns in os.walk(cdr):
|
|
if di == cdr:
|
|
pass
|
|
else:
|
|
files_origin.extend([os.path.join(di,f) for f in fns])
|
|
|
|
|
|
for src_file in files_origin:
|
|
fname = os.path.basename(src_file)
|
|
targ_file = os.path.join(cdr, fname)
|
|
os.rename(src_file, targ_file)
|
|
|
|
|
|
dirs_purge = list()
|
|
for di, dnames, fns in os.walk(cdr):
|
|
for d in dnames:
|
|
cpath = os.path.join(di, d)
|
|
fna = [x for x in list_files(cpath)]
|
|
if len(fna) == 0:
|
|
dirs_purge.append(cpath)
|
|
|
|
for d in dirs_purge:
|
|
if os.path.exists(d):
|
|
shutil.rmtree(d)
|
|
|
|
|
|
|
|
|
|
|