We have one requirement in our project that detect anything that is dropped into a directory in python.
The process is like this:
There will be a python script running almost all time a day(sort of cron job), which will keep watch on a directory.
When anybody puts a file into a directory that file should be detected.
- File dropped will have zip, xml, json or an ini format.
- There is no fix way that how user will drop the file into that directory (i.e person could simply copy or move it using
console
bycp or mv
command. Or person might do aFTP transfer
from some other computer, or may upload it through ourweb interface
)
I'm able to detect it while dropped by web interface but not for other ways.
Can anyone suggest me the way to detect file dropped:
def detect_file(watch_folder_path):
""" Detect a file dropped """
watched_files = os.listdir(watch_folder_path)
if len(watched_files) > 0:
filename = watched_files[0]
print "File located :, filename