import pathlib, itertools, glob, shutil import random # root dir path = 'D://tx//' # type file & max size (Kb) ftype = {'.py' : 10, '.txt' : 100, '.xyz' : 5, '.bak' : 1 } # sub dir name tdir= {'script', 'text', 'file', 'ddd' } # combinations of name of file combin=[1, 2, 3, 4, 5] for d in tdir: comb = itertools.combinations(combin, r=2) for a, b in comb: pathlib.Path(path, d).mkdir(parents=True, exist_ok=True) for ext, size in ftype.items(): name = f'{d}{a}{b}{ext}' pathlib.Path(path, d, name).touch(exist_ok=True) full_name=pathlib.Path(path, d, name) print("------",full_name) f=open(full_name,"wt") n=size*int(1024*(random.random()+1)) buf=n*ext[1:] f.write(buf) f.close()