#!/usr/bin/env python3
import os

def mv_qr(src, dst):
    basename = os.path.basename(src)
    if len(basename) < 2:
        raise Exception('invalid basename: %s' % basename)
    prefix = basename[:2]
    dd = os.path.join(dst, prefix)
    os.makedirs(dd, exist_ok=True)
    print("%s => %s" % (src, os.path.join(dd, basename)))
    os.rename(src, os.path.join(dd, basename))

def main():
    src = '/data/qrs/GYCY-241216-119-02'
    dst = '/data/qrs/tree'
    for r, ds, fs in os.walk(src):
        for f in fs:
            if f.endswith('.jpg'):
                mv_qr(os.path.join(r, f), dst)

if __name__ == '__main__':
    main()