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

Private GIT Repository
stable, day after meeting
[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, start=None, end=None, distinction_word='', copy=True):# move start ordered files from indir to outdir
7         l = sorted(ls(indir))
8         for filename in l[start:end]:
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/updated/infarctus/crop-mask', './sample/train/infarctus', 0, 800, distinction_word="-crop-mask") # move [0 -> 600] ordered files from param 1 to param 2
18         move('./generated/updated/infarctus/crop-mask', './sample/valid/infarctus', 800, 1100, distinction_word="-crop-mask")
19         move('./generated/updated/infarctus/crop-mask', './sample/test/infarctus', 1100, 1200, distinction_word="-crop-mask")
20         
21         move('./generated/updated/noinfarctus/crop-mask', './sample/train/noinfarctus', 0, 100, distinction_word="-crop-mask")
22         move('./generated/updated/noinfarctus/crop-mask', './sample/valid/noinfarctus', 100, 160, distinction_word="-crop-mask")
23         move('./generated/updated/noinfarctus/crop-mask', './sample/test/noinfarctus', 160, 200, distinction_word="-crop-mask")