Renaming a file the same as a variable

조회 수: 2(최근 30일)
Tyler Murray
Tyler Murray 2016년 10월 3일
댓글: Tyler Murray 2016년 10월 3일
I am trying to rename a file the same as a variable. The variable obviously will be string, its just so I can make my program even more automated. For example :
x = 'RenameTest'
movefile('Original.txt', '%s.txt', x)
That code doesn't work but is this possible to do?
  댓글 수: 2
Tyler Murray
Tyler Murray 2016년 10월 3일
Thanks Peter! Works great!

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

채택된 답변

dpb
dpb 2016년 10월 3일
As written, just
movefile('Original.txt', [x '.txt'])
More general and where you were probably trying to head would be something like
outfile=sprintf('%s.txt',newfilebase);
movefile(oldfile,outfile)
where oldfile is a string variable containing the original name.
  댓글 수: 1
Tyler Murray
Tyler Murray 2016년 10월 3일
Thanks dpb!

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by