1 from os import listdir as ls
2 from os.path import join, splitext
3 from shutil import move as mv, copyfile as cp
6 def move(indir, outdir, n, distinction_word='', copy=True):# move n ordered files from indir to outdir
9 # print(join(indir, filename), join(outdir, filename))
10 pathlib.Path(outdir).mkdir(parents=True, exist_ok=True)
11 fname, fextension = splitext(filename)
12 action = cp if copy else mv
13 action(join(indir, filename), join(outdir, fname + distinction_word + fextension))
15 if __name__ == '__main__':
17 move('./sample-crop-mask/train/infarctus', './generated/90/infarctus/crop-mask', 400) # move 400 ordered files from param 1 to param 2
18 move('./sample-crop-mask/train/noinfarctus', './generated/90/noinfarctus/crop-mask', 400)
19 move('./sample-crop-mask/valid/infarctus', './generated/90/infarctus/crop-mask', 100)
20 move('./sample-crop-mask/valid/noinfarctus', './generated/90/noinfarctus/crop-mask', 100)