Benny
09-29-2002, 01:42 AM
Hey all, I'm curious about the best way to achieve something like the following:
Lets say I need a program that constantly monitors an empty directory for a file type. Lets say a jpg image. Then once it detects the file, it does something with it. For the purpose of this lets say it moves it somewhere else.
So I know code such as this would work:
import glob, os
directory1 = "/images"
directory2 = "/images2"
while 1:
listing = glob.glob(os.path.join(directory1, "*.jpg"))
if listing != "":
for item in listing:
os.rename(item, os.path.join(directory2, os.path.basename(item))
However isn't it very bad practise to use "while 1" loops, hence I'd like to know what others think would be a good way to achieve this without the use of a "while 1" loop.
Cheers
Ben.
Lets say I need a program that constantly monitors an empty directory for a file type. Lets say a jpg image. Then once it detects the file, it does something with it. For the purpose of this lets say it moves it somewhere else.
So I know code such as this would work:
import glob, os
directory1 = "/images"
directory2 = "/images2"
while 1:
listing = glob.glob(os.path.join(directory1, "*.jpg"))
if listing != "":
for item in listing:
os.rename(item, os.path.join(directory2, os.path.basename(item))
However isn't it very bad practise to use "while 1" loops, hence I'd like to know what others think would be a good way to achieve this without the use of a "while 1" loop.
Cheers
Ben.