Filter löschen
Filter löschen

changing the name of the file that is corrupt

1 Ansicht (letzte 30 Tage)
Sanwal Yousaf
Sanwal Yousaf am 11 Mär. 2016
Kommentiert: Sanwal Yousaf am 24 Mär. 2016
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB 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!

Translated by