0

I am trying to make a simple piece of software that automatically makes a list based on the file contents of any newly inserted USB memory stick.

using ubuntu 14.04.

now using os.listdir() and glob.glob() work fine on their own...

however when using it with pyinotify, and getting the input_dir for the os.listdir() or glob.glob() from the event.pathname ... I just get a blank list every time...

tried concatenating strings to add single quotes, double quotes etc... to no avail.

here's a snippet of code

#!/usr/bin/python

#notifier setup
import pyinotify, os, glob

wm=pyinotify.WatchManager()

class EventHandler(pyinotify.ProcessEvent):
    def process_IN_CREATE(self,event):
        global path
        path = event.pathname
        usb_insertion()

def usb_insertion():
    print glob.glob(path+"/*")
    print "listdir", os.listdir(path)


handler=EventHandler()
notifier=pyinotify.Notifier(wm, handler)
wdd=wm.add_watch('/media', pyinotify.IN_CREATE, rec=True)

notifier.loop()
4

1 回答 1

1

如果有人感兴趣,我已经解决了这个问题。

在执行 glob 或 os.listdir() 之前添加 time.sleep(2) 似乎已经完成了。

于 2014-10-29T15:18:34.170 回答