0

I would like to run a python script on my Raspberry Pi which basically monitors the USB ports for insertion of a USB drive. Upon insertion it should copy files from the drive onto a local folder.

So far I've managed to use the pyudev library to monitor insertion and removal of USB drives and obtain the device path but I'm not sure on how to proceed with copying the files.

My code so far is below:

from pyudev import Context, Monitor, MonitorObserver

context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
def print_device_event(device):
    print('background event {0.action}: {0.device_path}'.format(device))
observer = MonitorObserver(monitor, callback=print_device_event, name='monitor-observer')
observer.daemon
observer.start()
Ailsor
  • 48
  • 5

1 Answers1

0

To copy files use:

import shutil
shutil.copyfile(src, dst)
FormulaRossa
  • 26
  • 1
  • 5