DEV Community

Cover image for Bulk converts files to QR codes
petercour
petercour

Posted on

Bulk converts files to QR codes

What's the craziest way to take backups? The cloud? floppy disks? QR codes?

QR codes started with the Japanese automobile industry. They are graphical codes you can use to store data.

You can quack QR codes with duckduckgo. Type "QR hello world" for it to generate a QR code containing "hello world". But did you know you can do it from code?

QR codes backup with Python

We'll convert files in bulk to QR codes with Python programming. This guide is for Linux computers.

Install zbar-tools and qrcode module

sudo apt install zbar-tools

Then you can convert all (.py) files in a directory to qr codes.

#!/usr/bin/python3
import qrcode
import glob

files = glob.glob("*.py")
for filename in files:
    data = ""
    with open(filename, 'r') as file:
            data = file.read()

    img = qrcode.make(data)
    img.save('qr-' + filename + '.png')

There's a limit to the file size, about 8 kilobytes. But for small files this actually works.

This creates a QR code when running the program for each python file in the directory (*.py).

You can decode a QR code with the command:

zbarimg qr-qrfs.py.png

Then you can print all your files on paper. If they files fit into the QR code that is.

Related links:

Top comments (0)