Load file as soon at saved from another session

2 次查看(过去 30 天)
Hi, I'm running two Matlab sessions. Is there anyway to load a file that is saved from another session, as soon as it is saved?
Is it possible to create a function that is continuously running and immediate loads files as they are saved from another session?
Thanks!
S

采纳的回答

Walter Roberson
Walter Roberson 2017-5-8
Caution: when you do this kind of directory watching, what you are checking is almost always that the target file is being created. That is quite different from the file being ready for use. It is not possible for the operating system to detect that a file is "ready for use" by another process; on most operating systems it is messy even just to detect whether some process has a particular file open.
Because of these difficulties, it is not a good idea to rely just upon a file's existence to determine whether that same file is ready for use. You need to develop protocols to signal that the file is ready.
There are methods such as using "lock files" or semaphores or shared memory segments or memmap() to communicate information about whether a file is ready for use or not.
One of the useful methods is to create the file using a different name than the second system is looking for, and do all the I/O to the file using that name, close the file, and then have the writing process rename the file to become the name that the second system is checking for. If you do this, then the fact that the expected file name has come into existence signals that the file is ready for use, because the writing system did not allow the file to be that name until the file was ready.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Files and Folders 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by