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,

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 3 Mär. 2013
Bearbeitet: Azzi Abdelmalek am 3 Mär. 2013

0 Stimmen

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

1 Kommentar

Walter Roberson
Walter Roberson am 3 Mär. 2013
Bearbeitet: Jan am 4 Mär. 2013
It would be movefile() rather than copyfile()

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 3 Mär. 2013
Bearbeitet: Walter Roberson am 3 Mär. 2013

0 Stimmen

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

2 Kommentare

Jan
Jan am 4 Mär. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 3 Mär. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by