1

i am using jnotify to get an event when a new file is created/copied in a certain directory. When the file is copied in the direcotry, I want to execute a tool with this file as parameter. Problem is: When the file size is large and not instantly copied in the directory, i can't start the tool with this file, because it's still copying this file.

Any suggesstions to solve this problem? Is there a way to check if a file is "ready"?

Fulley
  • 73
  • 6

2 Answers2

0

JNotify is hooking to the file system events, and you get what is reported by the OS. what you can do is to use a timer to wait for a second or two of inactivity for that file before activating your action.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • so there is no way to get also a notify for a ready file? i am trying to avoid polling, but if it's impossible, then i will poll it... thanks though – Fulley Dec 04 '13 at 09:28
  • no, there is no such concept as a ready file at the OS level (which is what JNotify is using). what I suggested it not pooling, rather waiting for the last write event from JNotify, where the last is defined as an event after which there were no additional events from the file for a second (for example) – Omry Yadan Dec 05 '13 at 19:13
0

Make sure that your file is open for use by using lsof command (Linux/Unix), so that you will not process the in-progress file (file is in use)

Shan
  • 1