Error using copyfile (Cannot copy or move a file or directory onto itself)

28 views (last 30 days)
I am trying to copy a file with name test_0 and paste it in same location with name test_1. Then i want to repeat this code with the numbers increasing by one in the file name. I wrote this code:
for i=1:100
Filename=strcat('test_',num2str(i));
Filename=strcat(Filename,'.xlsx');
FilenameR=strcat('test_',num2str(i-1));
FilenameR=strcat(FilenameR,'.xlsx');
copyfile (FilenameR),(Filename)
end
and i am getting an error:
Error using copyfile
Cannot copy or move a file or directory onto itself.
Error in File (line 19)
copyfile (FilenameR),(Filename)
What can i do.
  3 Comments

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 6 Feb 2020
Your copyfile sytnax is incorrect. Try this:
copyfile(FilenameR,Filename)

More Answers (0)

Categories

Find more on Startup and Shutdown 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!