How to determine if a file copy is completed using cocoa

白昼怎懂夜的黑 提交于 2019-12-22 15:02:06

问题


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


回答1:


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.




回答2:


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.




回答3:


you can check that whether the file you want to open is exist or not? and act accordingly.



来源:https://stackoverflow.com/questions/9139445/how-to-determine-if-a-file-copy-is-completed-using-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!