Effacer les filtres
Effacer les filtres

Renaming a file the same as a variable

5 vues (au cours des 30 derniers jours)
Tyler Murray
Tyler Murray le 3 Oct 2016
Commenté : Tyler Murray le 3 Oct 2016
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 commentaires
Peter Gruber
Peter Gruber le 3 Oct 2016
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 le 3 Oct 2016
Thanks Peter! Works great!

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 3 Oct 2016
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.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by