简体   繁体   English

Matlab批处理文件重命名器

[英]Matlab batch file renamer

I have a list of files and I need to rename everyone. 我有一个文件列表,我需要重命名每个人。 the files are called fileXXXUncomp.xml 这些文件称为fileXXXUncomp.xml

and I need to rename to fileXXX.xml . 并且我需要重命名为fileXXX.xml

I used dir('.xml') to list and to rename but I failed. 我使用dir('.xml')列出并重命名,但失败了。

Could anyone help? 有人可以帮忙吗?

Assuming that the files don't have dot(.) anywhere else except for the file extension part at the end, try this movefile based approach with cell arrays - (。)假设文件没有点任何地方,除了在最后的文件扩展部分,试试这个movefile基础的方法与细胞阵列-

org_fns = cellstr(ls('file*Uncomp.xml')) %// original filenames with given pattern

if ~isempty(org_fns{1}) %// Make sure we are processing something
    new_fns = strrep(org_fns,'Uncomp.xml','.xml')  %// new filenames
    cellfun(@(x1,x2) movefile(x1,x2), org_fns, new_fns) %// rename all those files
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM