File modification alert from windows api

조회 수: 3 (최근 30일)
Fedor Simkovic
Fedor Simkovic 2012년 2월 19일
편집: Image Analyst 2013년 10월 17일
Hello!
I want my matlab program to receive a notification from or through the windows api whenever a file is externally modified (a picture) so that it can immediately load the new file. I am basically trying to avoid using a timer function as that one only looks for changes once a time interval and when i make the interval too small it produces problems.
Thanks!
  댓글 수: 2
Oleg Komarov
Oleg Komarov 2012년 2월 19일
Too small how small?
Image Analyst
Image Analyst 2012년 2월 19일
What problems do you get? What's wrong with a timer? What file parameters are you checking? The date/time via fileinfo()?

댓글을 달려면 로그인하십시오.

채택된 답변

Jiro Doke
Jiro Doke 2012년 2월 20일
You may be able to use the .NET interface, using the FileSystemWatcher class.
Here's a simple example in MATLAB (assuming you have an image called "mypicture.jpg" in the current folder:
% Watch this folder
w = System.IO.FileSystemWatcher(pwd);
% Watch a particular image file
w.Filter = 'mypicture.jpg';
% Notify when the file changes
w.NotifyFilter = System.IO.NotifyFilters.LastWrite;
% Create a listener for change
addlistener(w, 'Changed', @changedFcn);
% Start watching.
w.EnableRaisingEvents = true;
You also need to create a function like this:
function changedFcn(obj, eData)
fprintf('Changed: %s\n', char(eData.FullPath));
end
Try modifying the image.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by