I figured it out. The read statement is what moves the file pointer, and if it gives an error then the pointer stays put. I solved the problem by making the read function fileparts, obtaining the filename from that, and then using try,catch with extractFileText on that file.
How do I skip a file that gives an error when using fileDatastore to loop through a folder of pdfs?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Allen
am 11 Jan. 2019
Kommentiert: Eniola Oluwakoya
am 29 Jul. 2020
I am mining text from several thousand pdfs in a folder using the Text Analytics Toolbox. I am using fileDatastore to loop through them. Some of the pdfs are encrypted, which gives an error with extractFileText. I have added a try,catch segment to skip those files, but when it catches the error it goes back to try and reads the same file again. The loop never ends. How do I increment the counter so that it will move on past the bad file? Here is part of the code:
fds = fileDatastore('File*.pdf','ReadFcn',@extractFileText);
while hasdata(fds)
% extract and prepare text
try % be prepared for error such as locked pdf
text=read(fds); % this is where error occurs
catch
disp('encrypted pdf');
continue
end
text=erasePunctuation(text);
% etc. (other text-parsing)
...
end
0 Kommentare
Akzeptierte Antwort
Allen
am 12 Jan. 2019
1 Kommentar
Eniola Oluwakoya
am 28 Jul. 2020
Hi, could you share more light on how you made the read function fileparts?
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!