Automatically execute code on last folder with files

1 visualización (últimos 30 días)
Konvictus177
Konvictus177 el 26 de Sept. de 2022
Respondida: chrisw23 el 26 de Sept. de 2022
Hi,
How can I force my code or any code to execute automatically when a new folder with data has been created and automatically select this new folder with data to be analyzed.
At the moment I collect a bunch of excel files that I store in a folder. In order to analyze the data collected I run the MATLAB code and select the folder that contains all excel files. When I collect data again, I create a new folder where I store all excel files. For analyzing the data I run the MATLAB code again where I select the new folder created.
How can I somehow force MATLAB to automatically wait for a new folder and if there is a new folder with data, MATLAB should execute automatically and analzye the data in the folder.
Does something like this exist?
Thanks.

Respuestas (1)

chrisw23
chrisw23 el 26 de Sept. de 2022
fsWatcher = System.IO.FileSystemWatcher()
% see events provided by
details(fsWatcher)
% register for event Changed Created or Deleted
liFsWatcher = addlistener(fsWatcher,"Created",@fsWatcher_Callback)
% use other .net Objects like DirectoryInfo to analyze or start processing
dInfo = System.IO.DirectoryInfo("C:\Temp")
...
fInfo = System.IO.FileInfo("C:\Temp\myFile.xyz")
function fsWatcher_Callback(src,evnt)
evnt % created event
...
end
If you are working under Windows, .net Framework provides a lot of functionality you could use.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by