rename files using "system" function

I want to rename my files using the "rename" command in "system" function like this:
oldname = 'Michael_Jackson-Beat_It.mp3"
newname = 'Michael Jackson - Beat It.mp3"
system(['rename ' oldname ' ' newname]);
I'm producing the "newname"s automatically from the oldnames and doing this in a huge for loop.
But it doesn't work when there's a space in the name strings, I think due to the "rename" command... How can I solve this problem?
thanks,

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 3일
편집: Azzi Abdelmalek 2013년 3월 3일

0 개 추천

oldname = 'Michael_Jackson-Beat_It.mp3'
newname = 'Michael Jackson - Beat It.mp3'
copyfile(oldname,newname)

댓글 수: 1

Walter Roberson
Walter Roberson 2013년 3월 3일
편집: Jan 2013년 3월 4일
It would be movefile() rather than copyfile()

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

Walter Roberson
Walter Roberson 2013년 3월 3일
편집: Walter Roberson 2013년 3월 3일

0 개 추천

system(['rename ''' oldname ''' ''' newname '''']);

댓글 수: 2

Under Windows I'd prefer the double quotes:
system(['rename "' oldname '" "' newname '"']);
Under non-Windows systems, if the file names contained dollar-signs, the dollar-signs would trigger substitution (or other effects) inside of double-quotes but not inside of single-quotes. For example,
copy "foo.bar" "foo-$PWD"
would trigger PWD to be expanded rather than being treated as a literal string.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by