I am developing folder watcher application for MAC in XCode using Foundation framework and FSEvents API. I need to know whether the file has been completely copied to the destination before I open the file for other operation. Is there any way of knowing it? please advice
Asked
Active
Viewed 623 times
3 Answers
1
I noticed that FSEvents API sends "create" event at beginning and "create-and-modify" at the end. On my project I used FSEventsStream with zero latency, and "NoDefer" flag on creation. Watching for "Modify" only events may give you information that file copy is completed.

Danil Korotenko
- 11
- 1
-
Using "lsof" will give you no sense, because different processes may open and close the file in undefined order. In addition you will ned to filter those processes names. – Danil Korotenko Dec 04 '16 at 10:01
-
"Finder" may take the file opened for a long time after copy finished. – Danil Korotenko Dec 04 '16 at 10:02
0
you can check that whether the file you want to open is exist or not? and act accordingly.

Prashant Bhayani
- 692
- 5
- 18
0
From simply studying the FSEvents API I would say that what you want is not possible. I could be mistaken, though, I have never used FSEvents myself. The asker of this question has solved the problem by separately monitoring the new file with lsof
.