Hi,
Assume that I have a target directory, which I am using as a location to store my python scripts.What I need to do is to listen to that directory and when a python script is placed in that directory, I need to execute it at that time.Can anyone give me an idea on how to do this using python?

Recommended Answers

All 2 Replies

The listening part is the challenging bit. Are you planning on running a background thread or something?

Anyways, you'll end up doing something like this:

old_dir = os.listdir("mytargetdir")
while True:
     new_dir = os.listdir("mytargetdir")
     for x in new_dir:
         if x not in old_dir:
             f = open("mytargetdir/"+x)
             exec f
     old_dir = new_dir
     time.sleep(1000)  # 16 minutes

That's the general idea, but there might be better ones out there.

Jeff

thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.