how to run a python script after detect the insertion of usb drive

487 Views Asked by At

I have 2 python scripts

  1. the first detect the last insert USB drive.
  2. the second is to perform a backup of the folders and files from a USB drive .

detectusb.py

import win32api
import win32file

# Returns a list containing letters from removable drives
drive_list = win32api.GetLogicalDriveStrings()
drive_list = drive_list.split("\x00")[0:-1]  # the last element is ""

for letter in drive_list:
    if win32file.GetDriveType(letter) == win32file.DRIVE_REMOVABLE:# check if the drive is of type removable 

print("list drives: {0}".format(letter))

What i want is to combine these t scripts and run the first script once the user insert the USB i don't know if the cron will do the job but i need to run the script like autorun.

0

There are 0 best solutions below