Add movefile condition in Matlab
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a question. I've that code and I want to know if it's possible to add a condition to the movefile new name.
clc
clear all
Path = 'C:\EXE1\result\1\'; % path to the files
fileNames= {'0301975168AAA01.tar.gz', '45465456468AAA01.tar.gz'}
for k = 1:length(fileNames)
newFileName = ['fiche' fileNames{k} (3) '_pd_' fileNames{k}(3:5) '.tar.gz'];
% renaming
movefile([Path fileNames{k}], [Path newFileName]);
end
So, my condition would be something like this, for example:
This is one of my files
'0301975168AAA01.tar.gz'
And this is the the result after running the code:
fiche0_pd_01.tar.gz
And the condition will be:
fileNames{k} (3)>0-5 = 2
fileNames{k} (3)>5-10 = 2
So, in that case=
fileNames{k} (3)= 0 So it would be 2, not 0
fiche2_pd_01.tar.gz
Does somebody know how can I do it?
Thanks in advance and greetings,
4 个评论
回答(1 个)
Walter Roberson
2012-10-16
Use lookup tables.
For example, supposing 5 was to be left alone and 7 was to become 5 and the other digits were to become 2:
lookup3 = '2222252522';
newdigit = lookup3(fileNames{k}(3)-'0'+1);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!