]> AND Private Git Repository - myo-class.git/blob - tosampledir.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
1846c1d10a7f5764450d425288f18162fabb12a5
[myo-class.git] / tosampledir.py
1 from os import listdir as ls
2 from os.path import join, splitext
3 from shutil import move as mv, copyfile as cp
4 import pathlib
5
6 def move(indir, outdir, n, distinction_word='', copy=True):# move n ordered files from indir to outdir
7         l = sorted(ls(indir))
8         for filename in l[:n]:
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
14
15 if __name__ == '__main__':
16         
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")