Hi I am just wondering if any one has a simple solution for the above problem. Basically I would like to poll a folder to check as new files arrive and then do my processing on file.
I am just wondering if anyone has built\seen as elegant & simple solutions Two approaches I am considering would be a simple wait statement between checking folder or creating a listener. The listener would be more elegant but less simple.
Any comments? Any alternative approaches?
The men of Ireland were hurling when the gods of Greece were young
How do you define "new"? If i modify an existing file, is that new? what if the file is deleted, then restored, but the contents haven't changed?
How you define "new" is going to influence what you do
Never ascribe to malice that which can be adequately explained by stupidity.
Joined: Jul 27, 2006
Hi My approach would be A Identify file, open file B Process contents of file C Move file to processed or rejected as appropriate
So all files in folder will be processed, but once this is done they will be moved. So renaming should matter. If same content arrive a second time with new file name, then that file will also be processed
Java's Timer is a good way to schedule periodic operations like checking for new files. As Fred pointed out, deciding what's new may be as simple as timestamp > last run or as complex as your business rules make it.
And "listener" is also a good concept, too. Rather than making the directory checker do any real work with the files it finds, have it broadcast a "New File Found" event to one or more listeners. That helps the checker and the listener both do just one thing well.
If you were going to be doing a lot of this, you could wind up with a package containing a directory checker, an interface for plug-in Strategies for deciding what's new and a listener interface that clients could implement and subscribe to new file events. You could use it for any number of purposes without ever touching the code again. That's just an old geek wandering off the path ... do the simplest thing that works for now.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi