X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/myo-class.git/blobdiff_plain/c67ab60de95008178e26817946990382751d91d8..HEAD:/tosampledir.py?ds=sidebyside diff --git a/tosampledir.py b/tosampledir.py index 87effac..98d9aa5 100644 --- a/tosampledir.py +++ b/tosampledir.py @@ -1,18 +1,23 @@ from os import listdir as ls -from os.path import join -from shutil import move as mv +from os.path import join, splitext +from shutil import move as mv, copyfile as cp import pathlib -def move(indir, outdir, n):# move n ordered files from indir to outdir +def move(indir, outdir, start=None, end=None, distinction_word='', copy=True):# move start ordered files from indir to outdir l = sorted(ls(indir)) - for filename in l[:n]: + for filename in l[start:end]: # print(join(indir, filename), join(outdir, filename)) pathlib.Path(outdir).mkdir(parents=True, exist_ok=True) - mv(join(indir, filename), join(outdir, filename)) + fname, fextension = splitext(filename) + action = cp if copy else mv + action(join(indir, filename), join(outdir, fname + distinction_word + fextension)) # distinction_word='-mask'; /path/file.jpg => /path/file-mask.jpg if __name__ == '__main__': - move('./train/infarctus', './sample/train/infarctus', 1000) # move 1000 ordered files from param 1 to param 2 - move('./train/noinfarctus', './sample/train/noinfarctus', 1000) - move('./train/infarctus', './sample/valid/infarctus', 300) - move('./train/noinfarctus', './sample/valid/noinfarctus', 300) \ No newline at end of file + 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 + move('./generated/updated/infarctus/crop-mask', './sample/valid/infarctus', 800, 1100, distinction_word="-crop-mask") + move('./generated/updated/infarctus/crop-mask', './sample/test/infarctus', 1100, 1200, distinction_word="-crop-mask") + + move('./generated/updated/noinfarctus/crop-mask', './sample/train/noinfarctus', 0, 100, distinction_word="-crop-mask") + move('./generated/updated/noinfarctus/crop-mask', './sample/valid/noinfarctus', 100, 160, distinction_word="-crop-mask") + move('./generated/updated/noinfarctus/crop-mask', './sample/test/noinfarctus', 160, 200, distinction_word="-crop-mask")