dir-command: import only files that have datenum between two dates
古いコメントを表示
Hi everyone,
I am using the dir-command to get file information of many files in a directory (>800 000 files).
However, I only need the files with datenum between 01.01.2018 and 01.01.2019, which are significantly less files.
I was trying to work with cellfun, as shown in the MATLAB documentation of the dir command (https://de.mathworks.com/help/matlab/ref/dir.html):
MyFolderInfo = dir;
MyFolderInfo = MyFolderInfo(~cellfun('isempty', {MyFolderInfo.date}));
This is my current status:
date_2018 = datenum('2018/01/01 00:00:00','yyyy/mm/dd HH:MM:SS');
date_2019 = datenum('2019/01/01 00:00:00','yyyy/mm/dd HH:MM:SS');
listdir = dir(some_path);
listdir = listdir(cellfun(@(s) {s.datenum}<date_2019 && {s.datenum}>date_2018));
This gives the error:
Error using cellfun
Not enough input arguments.
So, obviously I'm not good with cellfun in general, but this is an example where I wanted to learn a bit about this tool.
Can anyone help me with this task?
Firstly, it's about getting rid of the not needed entries in the struct-variable. If this can be done with cellfun, that would be nice.
Thanks a lot in advance!
JE
採用された回答
その他の回答 (1 件)
Bob Thompson
2019 年 1 月 31 日
編集済み: Bob Thompson
2019 年 1 月 31 日
0 投票
I don't know that cellfun is going to work on the dir results because they are an array of structures. You should be able to solve this using indexing alone.
Something like:
listdir = [listdir.date >= date2018 & listdir.date<= date2019];
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!