copy a string from filename and detect a new file in the folder

조회 수: 1 (최근 30일)
Win co
Win co 2012년 5월 4일
Hi,
I have a list of files like that :
data_acc_13042012.mat
data_acc_15042012.mat
data_acc_25042012.mat
data_acc_02052012.mat
the numbers correspond to date, for ex : 13/04/2012
Firstly,I would like to extract only the numbers in the filename and save them to a vector "date". Then I will display my data following this vector "date".
Secondly, for each time I run my code, I would like to detect if a new data file is added, for ex : data_acc_10052012.mat, etc. If yes, I redo the extraction of date and add it to the vector "date".
May anyone have an idea to do all these things please ?
Thanks for all your answers
Winn
  댓글 수: 1
Jan
Jan 2012년 5월 4일
As usual it would be helpful if you show, what you have tried so far. I could imagine, that you have at least some lines of the code including the DIR command. If you post this, our suggestion could match your code.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 5월 4일
function ShowFiles(Folder)
persistent shownAlready
list = dir(fullfile(Folder, '*.mat'));
name = {list.name};
if ~isempty(shownAlready)
name_bak = name;
name = setdiff(name, shownAlready);
shownAlready = name_bak;
end
blockStr = sprintf('%s;', name{:});
number = sscanf(blockStr, 'data_acc_%2d%2d%4d.mat;');
dateV = transpose(reshape(number, 3, []));
dateD = datenum(dateV(:, 3), dateV(:, 2), dateV(:, 1));
[dum, order] = sort(dateD);
for i = order
<do something with the file: fullfile(Folder, name{i})>
end
  댓글 수: 1
Win co
Win co 2012년 5월 4일
It works greatly your code. It's very kind of you to help me.
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by