Wait for complete file transfer before running while loop
6 ビュー (過去 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 で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!