Using AppDesigner with FileSystemWatcher
显示 更早的评论
I am trying to create a MATLAB app that uses FileSystemWatcher to call an event handler each time a specific file has changed--using version 2018b. I have created the following two functions in Code View using the appdesigner; however the app never calls 'eventhandlerChanged' function. I've spent a lot of time trying to get this to work, so any help would be greatly appreciated.
% Button pushed function: TestFSWButton
function AddFSW(app, event)
fileObj = System.IO.FileSystemWatcher('D:\Matlab\Work');
fileObj.Filter = 'test.csv';
fileObj.EnableRaisingEvents = true;
addlistener(fileObj,'Changed',@app.eventhandlerChanged);
end
function eventhandlerChanged(app,evt)
tic;
toc;
end
6 个评论
Geoff Hayes
2020-6-29
Darrell - have you tried removing the filter or just using '*.csv'? Have you tried using code similar to the above but not from within App Designer?
Darrell
2020-6-29
Darrell
2020-6-29
Geoff Hayes
2020-6-29
Darrell - from Create event listener bound to event source it shows that the call to addlistener returns an object. I wonder if you need to make that object a member of your app? (i.e. assign the result of this call to a member within your App class.) Because if you don't do this, then the local object - created within the AddFSW method - would be destroyed as the method completes and you would no longer have an object listening for changes to your file. (?)
Darrell
2020-6-29
Geoff Hayes
2020-6-30
Glad it worked out! :)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Desktop 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!