rename files using "system" function
2 次查看(过去 30 天)
显示 更早的评论
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,
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-3-3
编辑:Azzi Abdelmalek
2013-3-3
oldname = 'Michael_Jackson-Beat_It.mp3'
newname = 'Michael Jackson - Beat It.mp3'
copyfile(oldname,newname)
1 个评论
Walter Roberson
2013-3-3
编辑:Walter Roberson
2013-3-3
system(['rename ''' oldname ''' ''' newname '''']);
2 个评论
Jan
2013-3-4
Under Windows I'd prefer the double quotes:
system(['rename "' oldname '" "' newname '"']);
Walter Roberson
2013-3-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!