text_plain_output_1.png
working_path = Path.cwd()
folders = ('train', 'test')
labels = ('0', '1')

input_path = Path('/kaggle/input')
train_image_paths = sorted(input_path.rglob('train/*.png'))
test_image_paths = sorted(input_path.rglob('test/*.png'))

try:
    for image_path in train_image_paths:
        if '_1' in image_path.stem:
            with (working_path / 'train' / '1' / image_path.name).open(mode='xb') as f:
                f.write(image_path.read_bytes())
        else:
            with (working_path / 'train' / '0' / image_path.name).open(mode='xb') as f:
                f.write(image_path.read_bytes())
except FileExistsError:

try:
    for image_path in test_image_paths:
        if '_1' in image_path.stem:
            with (working_path / 'test' / '1' / image_path.name).open(mode='xb') as f:
                f.write(image_path.read_bytes())
        else:
            with (working_path / 'test' / '0' / image_path.name).open(mode='xb') as f:
                f.write(image_path.read_bytes())
except FileExistsError:
    print('Testing images have already been moved.')
else:
    print('Testing images moved.')