Wait for complete file transfer before running while loop
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am using a while loop to monitor a folder for new files. My code process the new files (images and txt in a subfolder) transferred to the folder every 5 min. However, if my loop is initiated while a new folder is still transferred to the monitored folder I get an error. How can I pause the while loop if new files are transferred at the same moment? I was thinking something like sum the files sizes two times and if size 2 is increasing compared to size 1 then pause for 30 sec. But is there a more elegant way to do this? I need to compile my function and therefor not using the .net watch function.
0 comentarios
Respuestas (1)
James Browne
el 12 de Jun. de 2019
Greetings,
I am by no means an expert in programming but I had an idea that might be a good workaround. Let's say you don't try to wait for the file transfer to be complete, explicity, couldn't you find a way to identify what the last file name should be and check for it then have some logic statement like:
while (~lastFileNameExists)
%read file names;
if (last file == expectedLastFileName)
lastFileNameExists = true;
end
end
%process data;
The syntax is obviously not correct but the concept is to trap the processor in the while loop and force it to keep reading the list of file names until it finds that the last file name is present, which indicates that the file transfer is complete. If you don't know what the last file name is going to be (because it is not unique, etc), could you just put a blank file in at the end of the file transfer and look for the blank file's name to appear to indicate that the file transfer is complete?
Hope that at least points you in the right direction~
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!