Effacer les filtres
Effacer les filtres

Help with if-else statement?

2 vues (au cours des 30 derniers jours)
Lianna Johnson
Lianna Johnson le 5 Juin 2013
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

Réponse acceptée

Jan
Jan le 5 Juin 2013
Modifié(e) : Jan le 5 Juin 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);

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 5 Juin 2013
Modifié(e) : Azzi Abdelmalek le 5 Juin 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
  1 commentaire
Jan
Jan le 5 Juin 2013
Modifié(e) : Jan le 5 Juin 2013
I suggest to replace:
idx = cellfun(@(x) ~isempty(regexp(x,'201305')),f)
by
idx = strncmp(f, '201305', 6);

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by