lola
lola

Reputation: 5799

rename file using matlab command

file1 = fullfile(pwd,'folder','toto.txt');
file2 = fullfile(pwd,'folder','toto2.txt.sav');

movefile(file1,file2)

=>this creates a folder named toto2.txt.sav whereas I'm looking for renaming the file in the same directory

any idea ?

Upvotes: 3

Views: 25988

Answers (2)

Daniel
Daniel

Reputation: 36720

Check the documentation:

Renaming a File in the Current Folder
In the current folder, rename myfunction.m to oldfunction.m: movefile('myfunction.m','oldfunction.m')

Thus:

o=pwd
cd('folder')
movefile('toto.txt','toto2.txt.sav')
cd(o);

Upvotes: 3

Leo
Leo

Reputation: 1777

Was looking for this as well. Now on a windows machine if I want to rename all files in a folder, I do:

system('rename *.* *.sav')

Upvotes: 0

Related Questions