MATLAB: Do I get an error about priveleges when I use COPYFILE in MATLAB 7.14 (R2012a)

MATLAB

I have a file "foo.txt" and a folder "bar/", both in my current working directory. I am trying to copy the "foo.txt" into "bar/" using the COPYFILE function like this:
copyfile('foo.txt','/bar/');
However, when I do this, I get the following error:
Error using copyfile
A required privilege is not held by the client.

Best Answer

This is likely occurring due to a typographical error. The leading slash (/) character before "bar/" indicates the root directory, not the current directory. Therefore, COPYFILE is really creating a new directory "bar/" inside the root directory, which you may not have permissions to do.
To resolve this, simply remove the leading slash like this:
copyfile('foo.txt','bar/');