copy a string from filename and detect a new file in the folder
1 次查看(过去 30 天)
显示 更早的评论
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
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!