Help with if-else statement?
2 views (last 30 days)
Show older comments
Hi. So I have these files...
'20130401_SPLBRENT3_concat.mat'
'20130402_SPLBRENT3_concat.mat'
'20130403_SPLBRENT3_concat.mat'
'20130404_SPLBRENT3_concat.mat'
'20130405_SPLBRENT3_concat.mat'
'20130410_SPLBRENT3_concat.mat'
'20130411_SPLBRENT3_concat.mat'
'20130422_SPLBRENT3_concat.mat'
'20130424_SPLBRENT3_concat.mat'
'20130425_SPLBRENT3_concat.mat'
'20130426_SPLBRENT3_concat.mat'
'20130427_SPLBRENT3_concat.mat'
'20130429_SPLBRENT3_concat.mat'
'20130430_SPLBRENT3_concat.mat'
'20130501_SPLBRENT3_concat.mat'
'20130502_SPLBRENT3_concat.mat'
'20130503_SPLBRENT3_concat.mat'
'20130506_SPLBRENT3_concat.mat'
'20130517_SPLBRENT3_concat.mat'
'20130518_SPLBRENT3_concat.mat'
'20130519_SPLBRENT3_concat.mat'
'20130520_SPLBRENT3_concat.mat'
'20130521_SPLBRENT3_concat.mat'
'20130522_SPLBRENT3_concat.mat'
'20130523_SPLBRENT3_concat.mat'
'20130524_SPLBRENT3_concat.mat'
'20130527_SPLBRENT3_concat.mat'
'20130528_SPLBRENT3_concat.mat'
'20130529_SPLBRENT3_concat.mat'
'20130530_SPLBRENT3_concat.mat'
'20130531_SPLBRENT3_concat.mat'
These are data files from April (201304) and May (201305). I am trying to do an "if else" statement that will send the files with the first numbers 201304 to the path 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1304' and the files with the numbers 201305 to the path 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1305'. Notice that files aren't there from every day, so they're not a sequence. I'm pretty sure this is done with "if else" but I am not sure.
Can anyone help?
Thanks
0 Comments
Accepted Answer
Jan
on 5 Jun 2013
Edited: Jan
on 5 Jun 2013
Let the OS perform the pattern matching:
Dest1 = 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1304';
Dest2 = 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1305';
Source = 'D:\ParentFolderOfYourFiles';
movefile(fullfile(Source, '201304*.mat'), Folder1);
movefile(fullfile(Source, '201305*.mat'), Folder2);
0 Comments
More Answers (1)
Azzi Abdelmalek
on 5 Jun 2013
Edited: Azzi Abdelmalek
on 5 Jun 2013
fic=dir('current_path/*.mat')
f={fic.name}
idx=cellfun(@(x) ~isempty(regexp(x,'201305')),f)
for k=1:numel(idx)
a1=fullfile('current_path/' f{idx});
a2=fullfile('path1/' f{idx});
movefile(a1,a2)
end
idx1=cellfun(@(x) ~isempty(regexp(x,'201304')),f)
for k=1:numel(idx1)
a1=fullfile('current_path/' f{idx1});
a2=fullfile('path2/' f{idx1});
movefile(a1,a2)
end
See Also
Categories
Find more on Test Cases and Iterations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!