0

I have a folder on my windows 7 pc, that once a file was copied successful to my folder - I would like to invoke ant script/call java code that will accept the file name and location.

How can I do it?

1 Answer 1

1

In Windows 7, there is a built-in Task Scheduler [1]. You could write a Java class (or Ant script) that would execute every 5 minutes, for example, check the files on that folder and perform an action on any file in it.

Of course, this implies a certain delay in processing the file; and if you reduce the delay, then you will likely have to control concurrent access if two instances of the job end up overlapping, but it could be a start.

[1] http://windows.microsoft.com/en-US/windows7/schedule-a-task

Also see: Run script on Windows every n minutes

2
  • What is the best way to know that the file copy was finished? maybe it's in the middle?
    – Dejel
    Commented Feb 15, 2011 at 15:37
  • Some quick searches indicate there is no definitive solution to this. One option is to observe the file's last modification date. For example, files unchanged in the last 3 minutes are likely to be finished. Another option is to detect that the file is in transit (example: if there is a file a.txt and a file a.txt.part, it means it's still in progress. Maybe only the .part file exists, in this case it will be renamed when finished and you can just ignore it for now). This would depend on who puts the file on your folder and how (nfs share? samba? simple copy on the same machine?).
    – st.never
    Commented Feb 15, 2011 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .