Using AppDesigner with FileSystemWatcher
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 29 de Jun. de 2020
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
el 29 de Jun. de 2020
Darrell
el 29 de Jun. de 2020
Geoff Hayes
el 29 de Jun. de 2020
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
el 29 de Jun. de 2020
Geoff Hayes
el 30 de Jun. de 2020
Glad it worked out! :)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Desktop en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!