필터 지우기
필터 지우기

Wait for complete file transfer before running while loop

조회 수: 11 (최근 30일)
Johnny Birch
Johnny Birch 2019년 6월 12일
답변: James Browne 2019년 6월 12일
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.

답변 (1개)

James Browne
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~

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by