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

조회 수: 11 (최근 30일)
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
Stephen23
Stephen23 2020년 2월 6일
"I think the syntax is just supposed to be copyfile FilenameR Filename"
Nope, that won't work:
Jakob B. Nielsen
Jakob B. Nielsen 2020년 2월 6일
Woop! Learning something new every day.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2020년 2월 6일
Your copyfile sytnax is incorrect. Try this:
copyfile(FilenameR,Filename)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by