%% Copy and Rename File to Read-Only Folder
% Copy the file myfile1.m from the current folder to the read-only folder  restricted and rename it to myfile2.m.
% Create the read-only folder restricted.

mkdir restricted
fileattrib restricted -w

%
% Copy and rename the file myfile1.m. A status of 0 shows the copy was unsuccessful, and message describes the issue.

[status,message,messageId] = copyfile('myfile1.m', 'restricted\myfile2.m')

%
% Copy and rename the file myfile1.m using the 'f' option to override. A status of 1 and an empty message and messageID confirms the copy was successful.

[status,message,messageId] = copyfile('myfile1.m', 'restricted\myfile2.m', 'f')

% Copyright 2012 The MathWorks, Inc.