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

You are amost there. The right way to do it is
x = 'RenameTest'
movefile('Original.txt', [x '.txt'])
or, if you really want to use the formatting string (not really needed)
x = 'RenameTest'
movefile('Original.txt', sprintf('%s.txt', x))
Tyler Murray
Tyler Murray 2016년 10월 3일
Thanks Peter! Works great!

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

 채택된 답변

dpb
dpb 2016년 10월 3일

0 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2016년 10월 3일

댓글:

2016년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by