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 Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by