Clear Filters
Clear Filters

changing the name of the file that is corrupt

1 view (last 30 days)
I am running a script where i load .cnt files and reaction files that are stored as a .txt files. What i didn't realize is that there was one file that was corrupt and that caused my script to not work. I took care of that without any trouble. However, this got me thinking of what would happen in the future. Since this is a lab where i work at people tinker with those files and sometimes this said tinkering could cause it to not function. Is there a way where i could specify the errors that i could get and if the script comes across those errors, the code would then mark them as corrupt and notify the user that they need to be taken out of the data run.

Accepted Answer

Image Analyst
Image Analyst on 11 Mar 2016
Yes, just use try catch
for k = 1 : numberOfSelectedFiles
try
% read file
% if it works it does more code.
catch
% File can't be read - it's corrupt. Alert the user.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
continue; % Skip to bottom of for loop and continue with the next iteration.
end
end % of for loop

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!