import plac
from unlzw import unlzw
from pathlib import Path


@plac.pos('csv_dir', '', type=Path)
def main(csv_dir):
    for zip_file in csv_dir.glob('*Z.*'):
        if zip_file.is_dir():
            continue
        # print(zip_file.stat())
        size = zip_file.stat().st_size
        if size > 100:
            new_file = str(zip_file)[:-8] + str(zip_file)[-1:] + '.csv'
            try:
                with open(zip_file, 'rb') as zip:
                    with open(new_file, 'wb') as f_out:
                        f_out.write(unlzw(zip.read()))
            except OSError:
                print(str(zip_file) + ": " + str(size))


if __name__ == '__main__':
    # plac.call(main)
    main(Path('C:\\GlobalCube\\System\\AUTOLINE\\Datenbank\\Full_zusammengesetllt'))