X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/myo-class.git/blobdiff_plain/d983932e5a974928a10bbab7e86fdf3e162ae2ae..bdfe02afe03428e59b3c85b6cae19d579d82f55c:/tosampledir.py?ds=inline diff --git a/tosampledir.py b/tosampledir.py index 87effac..1846c1d 100644 --- a/tosampledir.py +++ b/tosampledir.py @@ -1,18 +1,20 @@ 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, n, distinction_word='', copy=True):# move n ordered files from indir to outdir l = sorted(ls(indir)) for filename in l[:n]: # 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/90/infarctus/crop-nomask', './sample/train/infarctus', 400, distinction_word="-crop-nomask") # move 400 ordered files from param 1 to param 2 + move('./generated/90/noinfarctus/crop-nomask', './sample/train/noinfarctus', 400, distinction_word="-crop-nomask") + move('./generated/90/infarctus/crop-nomask', './sample/valid/infarctus', 100, distinction_word="-crop-nomask") + move('./generated/90/noinfarctus/crop-nomask', './sample/valid/noinfarctus', 100, distinction_word="-crop-nomask") \ No newline at end of file