Using AppDesigner with FileSystemWatcher
Mostra commenti meno recenti
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 Commenti
Geoff Hayes
il 29 Giu 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
il 29 Giu 2020
Darrell
il 29 Giu 2020
Geoff Hayes
il 29 Giu 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
il 29 Giu 2020
Geoff Hayes
il 30 Giu 2020
Glad it worked out! :)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Desktop in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!