Wait for complete file transfer before running while loop
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
James Browne
2019-6-12
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!