MATLAB: How to ask user before overwriting a text file

askuserfopenfprintfoverwriterewrite

Hi, I want to write some data from MATLAB to a text file. But I want if the text file existed, ask the user if they want to overwrite the text file. Any suggestion?
Thanks
P.S. I'm writing the text files using:
fileID = fopen('Test.txt','w');
fprintf(fileID,'Hello!');

Best Answer

if exist('Test.txt','file')
%%do what you want
end
doc exist
You have to check this before opening file for writing, else it opens fresh file after fopen.
Related Question