"delete" does not find a file?

조회 수: 23 (최근 30일)
Danijel Domazet
Danijel Domazet 2020년 5월 13일
댓글: Walter Roberson 2020년 5월 13일
Why wouldn't this work:
if isfile(filename)
delete filename
end
filename is a char vector.
File is not deleted, and I get a warning: Warning: File 'filename' not found.
How could it be not found if isfile returned true? Am I doing some beginer mistake?
  댓글 수: 2
Stephen23
Stephen23 2020년 5월 13일
"Why wouldn't this work: "
Because you are using outdated, misleading, sadly overused command syntax.
Use function syntax instead.
Danijel Domazet
Danijel Domazet 2020년 5월 13일
Will do, thanks.

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 13일
if isfile(filename)
delete(filename)
end
  댓글 수: 2
Danijel Domazet
Danijel Domazet 2020년 5월 13일
Thanks.
:-)
Walter Roberson
Walter Roberson 2020년 5월 13일
Look at the example,
delete *.mat
That is not going to ask MATLAB to look at all variables that are in scope and see if they are structs with field named mat, or objects with property named mat, or objects with method named mat, and then evaluate as appropriate in order to get the names of the files to delete. NOT done.
Instead it is treated as
delete('*.mat')
which tells it to delete all files in the current directory whose extension is .mat

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by