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)) # distinction_word='-mask'; /path/file.jpg => /path/file-mask.jpg
15 if __name__ == '__main__':
17 move('./generated/90/infarctus/crop-nomask', './sample/train/infarctus', 400, distinction_word="-crop-nomask") # move 400 ordered files from param 1 to param 2
18 move('./generated/90/noinfarctus/crop-nomask', './sample/train/noinfarctus', 400, distinction_word="-crop-nomask")
19 move('./generated/90/infarctus/crop-nomask', './sample/valid/infarctus', 100, distinction_word="-crop-nomask")
20 move('./generated/90/noinfarctus/crop-nomask', './sample/valid/noinfarctus', 100, distinction_word="-crop-nomask")