Load file as soon at saved from another session

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 8 May 2017
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.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!